views:

138

answers:

1

What is the difference between git pull origin master and git pull origin/master ?

+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
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
thank you calmh...this is good explanation.
Rachel
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
@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
@jefromi Ah. Yes.
calmh
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
@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