git fetch
updates the local copies of remote-tracking branches. If the remote you have configured is origin
(which is usually the case) then git fetch
will update origin/master
as well as any other branches that exist remotely. These branches point to the commit that the remote branches are currently on.
For example, consider this invocation of git log --pretty=oneline --abbrev-commit --graph --decorate --all
:
* 46960d3 (origin/master) Commit 5
* 8b050c8 Commit 4
* cee210b (HEAD, master) Commit 3
* 075aafe Commit 2
* 69ade0a Commit 1
In this case, git fetch
retrieved two new commits (4 and 5), but the local master
branch is still behind.
To rectify the situation, one must check out master
if it is not already checked out (git checkout master
) and then merge with the new commits (git merge origin/master
).
git pull
is effectively a synonym for "fetch from the remote that the current branch is tracking, then merge with the tip commit that was fetched." In this case it would be equivalent to git fetch origin && git merge origin/master
.