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:
git pull
= git fetch origin
+ git merge origin/master
(or whatever your upstream is)
git pull origin
= git pull
(as long as origin is your upstream remote)
git pull origin master
= git fetch origin master
+git merge FETCH_HEAD
git pull origin/master
: invalid unless you have a remote called "origin/master"
git pull origin HEAD:master
: Tries to directly reset you local master to whatever HEAD points to on origin. (Don't do this.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…