What is the difference between git pull origin master
and git pull origin/master
?
views:
138answers:
1
+4
A:
git pull origin master
will pull changes from the origin
remote, master
branch and merge them to the local checked-out branch.
git pull origin/master
will pull changes from the locally stored branch origin/master
and merge that to the local checked-out branch. The origin/master
branch is essentially a "cached copy" of what was last pulled from origin
, which is why it's called a remote branch in git parlance. This might be somewhat confusing.
You can see what branches are available with git branch
and git branch -r
to see the "remote branches".
calmh
2010-05-21 16:36:12
in case of `git pull origin master` will it always merge to the master branch, lets say am on another branch in my repo and then am doing above command, will it update my current branch with the origin remote changes or my master branch with the changes ?
Rachel
2010-05-21 16:38:52
thank you calmh...this is good explanation.
Rachel
2010-05-21 16:41:46
My answer was actually a bit incorrect. :) I've updated it. The answer to your question is that in either case, it will merge to your current branch. To avoid merging with your current branch you need to `git fetch` and the separately `git merge`.
calmh
2010-05-21 16:55:16
@calmh: `git merge` (and therefore `git pull`) always merges into the current branch. To merge with something other than your current branch, just check it out first.
Jefromi
2010-05-21 17:10:13
@jefromi Ah. Yes.
calmh
2010-05-21 17:27:25
um .. I don't see how 'origin/master' is any different from 'origin master'; they're both the master branch on origin. Can you actually give an example of when they would be different?
hasen j
2010-05-23 21:39:08
@hasen Try doing a "pull origin master" when you are disconnected from the network. Then try "merge origin/master" (you can't pull, since it's not a remote). One works, because it's local, and one doesn't.
calmh
2010-05-23 21:48:11