I could use a hand with learning how to push a local branch to a remote branch. Please see below. Help much appreciated!
The local branch was created after cloning the repo then doing
$ git checkout -b mybranch remotes/origin/mybranch
$ git branch -a
master
* mybranch
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/mybranch
But when trying to push changes back up:
$ git push mybranch mybranch
fatal: 'myb开发者_运维技巧ranch' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git push remotes/origin/mybranch mybranch
fatal: 'mybranch' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git push origin/mybranch mybranch
fatal: 'mybranch' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
As Abizern says, this works:
git push origin mybranch
But, to explain further, the mybranch part is a refspec. This specifies the remote ref which should be updated with the given local commit.
So, the command above is equivalent to:
git push origin mybranch:mybranch
or even:
git push origin mybranch:refs/heads/mybranch
and, indeed, since you're on the local mybranch, you could have done:
git push origin HEAD:mybranch
This is good to understand, because I often find myself doing things like:
git push origin HEAD^:mybranch
where you want to push all but the topmost patch to the remote branch.
Finally, if you want to delete the remote mybranch, you do:
git push origin :mybranch
Try
git push origin mybranch
This pushes your branch named mybranch to the remote named origin
This is an old question, but I used this page as a ref back in the day, and have an answer with a different perspective. From my experience, the best way is to tweak your config settings such that a git push
is all that you will have to enter in the end.
You will push to the same remote branch that you update your code from:
git config --global push.default upstream
And now, you set the remote branch as upstream (if it wasn't already):
git branch --set-upstream-to origin/the_master
- NOTE: Older versions can fall back upon this deprecated form of the command/.
git branch --set-upstream local_branch origin/the_master
You have two branches - a local and a remote. Doing a git pull
or git push
without args should, and will now, do what you want. This will not limit you to pushing to remote branches with the same name as the local one, as some of the above commands do.
One final thing I usually do: modify git pull
to change from this sequence:
git fetch && git merge [remote_upstream]
togit fetch && git rebase [remote_upstream]
With this command: git config --global branch.autosetuprebase remote
精彩评论