What is the difference between git pull origin master and git pull origin/master ?
3 Answers
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".
-
5@calmh:
git merge(and thereforegit pull) always merges into the current branch. To merge with something other than your current branch, just check it out first.– CascabelMay 21, 2010 at 17:10 -
2um .. 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?– hasenMay 23, 2010 at 21:39
-
89
git pull origin/mastermay have been a valid command when this was written, but nowadays (git 1.7.10.3) it fails withfatal: 'origin/master' does not appear to be a git repository(as it should - pull is always for pulling from remotes). Aug 6, 2012 at 7:48 -
6Why is git so confusing? So we have 4 repositories totally, correct? There is a (1) remote repository, (2) a local repository, (3) a staging repository, (4) a local-remote aka origin/master? Why would git have #4 repository at all?– MugenJul 28, 2019 at 14:25
-
2@Rachel, to answer your question, the term "master" in "git pull origin master" is referring to the source (not destination) branch; i.e., it will pull new changes from a branch named "master", on the remote named "origin" (default alias for the remote repo URL from which your HEAD branch was cloned), and then merge those changes into your local HEAD branch, i.e. the local branch that was "active"/checked out when u issued the command.– galaxisMay 7, 2021 at 20:54
git pull = git fetch + git merge origin/branch
git pull and git pull origin branch only differ in that the latter will only "update" origin/branch and not all origin/* as git pull does.
git pull origin/branch will just not work because it's trying to do a git fetch origin/branch which is invalid.
Question related: git fetch + git merge origin/master vs git pull origin/master
git pull origin master will fetch all the changes from the remote's master branch and will merge it into your local. We generally do not use git pull origin/master. We can do the same thing by git merge origin/master. It will merge all the changes from "cached copy" of origin's master branch into your local branch. In my case, git pull origin/master is throwing the error:
fatal: 'origin/master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
git pull origin/master. If you want to merge the [locally stored] remote branchorigin/master, just usegit merge origin/master.git pullmeansgit fetchfollowed bygit merge. It fetches the content from the remote, then merges it into your current branch. Butorigin/masteris a local branch (tracking a remote branch). If you want to merge it, you don't need to fetch anything. It's misleading to saygit pull origin/masterwhen you're not actually fetching from a remote.origin/masteris a locally stored branch that caches the master branch at the origin remote.