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.

Author: Yamaneko, 2014-01-30

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:

 73
Author: Rodrigo Deodoro, 2020-06-23 20:56:57

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.

 16
Author: Dio, 2014-01-30 18:13:11

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 by git merge FETCH_HEAD.

Git pull is a shortcut to git fetch followed by git merge FETCH_HEAD.

This default behavior can be changed to perform fetch + rebase , instead of fetch + merge, with the flag git pull --rebase

 11
Author: dcastro, 2014-01-30 17:13:55