Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push local master commits to remote branch

Tags:

git

I've been working on a local clone of a remote git repository, committing my changes to my local master branch. Now, I want to push my commits to the remote repository. However, I want to keep my local commits separate from the remote master branch, so that I don't break anything. How can I push my local commits to a new remote branch?

like image 225
Evan Kroske Avatar asked Jul 08 '10 16:07

Evan Kroske


2 Answers

You should run git help push, which will tell you about the syntax for the refspec that you push to. In short, git push <remotename> <local_branch_name>:<remote_branch_name>

like image 96
Daenyth Avatar answered Oct 12 '22 23:10

Daenyth


I was not able to do this with a single command. First I commit all my changes to my local master. Then I create a new local branch called "mybranch" using

git checkout -b mybranch

and then I pushed that using

git push -u origin mybranch

in my case origin is the remote name. Your remote name might be different. You can use git remote -v to see what your remote name should be.

After the push, if you want, you can get rid of your local branch using these two commands

git checkout master
git branch -d mybranch

hope that helps.

like image 38
John Henckel Avatar answered Oct 12 '22 23:10

John Henckel