What is the difference between the 'git pull' and 'git fetch' commands?
I would like to know what is the difference between git pull
and git fetch
commands in git versioning software.
3 answers
git fetch
download References (refs) with names or tags of one or more repositories (if you have another remote other than origin
configured), along with the objects needed to complete them. It basically updates local references with remote relationships, but does not merge with the local branch.
git pull
embeds changes from a remote repository to the local branch. Is equivalent to git fetch
followed by git merge FETCH_HEAD
.
References:
Simply put, git fetch
searches for differences from the current branch, but does not change anything in that branch. Already git pull
does the git fetch
and merges the differences.
git fetch
it downloads the latest commits from the remote branch, but does not embed them with the current copy of the repository. These commits will be available in Branch origin\master
, and branch master
remains intact.
pull
equivalent to doing git fetch
(download the latest commits) + git merge
(embed the commits with the local branch)
See git pull
manpage :
Git pull is shorthand for
git fetch
followed bygit merge FETCH_HEAD
.Git pull is a shortcut to
git fetch
followed bygit merge FETCH_HEAD
.
This default behavior can be changed to perform fetch
+ rebase
, instead of fetch
+ merge
, with the flag git pull --rebase