Differences between “git pull” commands when pulling from origin?

git pull is a convenience command, which is doing different things at the same time. Basically it is just a combination of git fetch, which connects to the remote repository and fetches new commits, and git merge (or git rebase) which incorporates the new commits into your local branch. Because of the two different commands involved the meaning of git pull is not always obvious.

You can configure an upstream for a local branch. After a fresh clone you will have a local branch “master”, a remote “origin” and your master branch has “origin/master” as upstream.
I assume this setup below. (You can see your upstream configuration with git branch -vv or by looking at .git/config.)

Now for your questions:

  1. git pull= git fetch origin + git merge origin/master (or whatever your upstream is)
  2. git pull origin = git pull (as long as origin is your upstream remote)
  3. git pull origin master = git fetch origin master+git merge FETCH_HEAD
  4. git pull origin/master : invalid unless you have a remote called “origin/master”
  5. git pull origin HEAD:master : Tries to directly reset you local master to whatever HEAD points to on origin. (Don’t do this.)

Leave a Comment