412

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

5
  • 2
    calmh pretty much has it covered, but the non-answer is that you shouldn't ever do git pull origin/master. If you want to merge the [locally stored] remote branch origin/master, just use git merge origin/master.
    – Cascabel
    Commented May 21, 2010 at 17:10
  • 3
    @Jefromi: Can you explain as to why it is always better to do git merge as compared to git pull ?
    – Rachel
    Commented May 21, 2010 at 17:14
  • 30
    git pull means git fetch followed by git merge. It fetches the content from the remote, then merges it into your current branch. But origin/master is a local branch (tracking a remote branch). If you want to merge it, you don't need to fetch anything. It's misleading to say git pull origin/master when you're not actually fetching from a remote.
    – Cascabel
    Commented May 21, 2010 at 17:24
  • Thanks Jefromi for the useful information. It really helps to understand pretty easily not so easy concept.
    – Rachel
    Commented May 21, 2010 at 17:39
  • 4
    For those reading this and still confused, origin/master is a locally stored branch that caches the master branch at the origin remote.
    – iheanyi
    Commented Dec 14, 2018 at 18:16

3 Answers 3

549

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".

10
  • 5
    @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.
    – Cascabel
    Commented May 21, 2010 at 17:10
  • 2
    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
    Commented May 23, 2010 at 21:39
  • 92
    git pull origin/master may have been a valid command when this was written, but nowadays (git 1.7.10.3) it fails with fatal: 'origin/master' does not appear to be a git repository (as it should - pull is always for pulling from remotes). Commented Aug 6, 2012 at 7:48
  • 6
    Why 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?
    – Mugen
    Commented Jul 28, 2019 at 14:25
  • 3
    @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.
    – galaxis
    Commented May 7, 2021 at 20:54
15

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

15

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.