Details and differences between Git fetch and pull

  • 2020-05-17 07:33:00
  • OfStack

The difference between git fetch and pull

In Git, there are two commands to get the latest version from the remote branch to the local:

1. git fetch: this is equivalent to getting the latest version from remote to local, not merge automatically


Git fetch origin master
git log -p master..origin/master
git merge origin/master

Meaning of the above command:

First download the latest version from the remote origin master main branch to the origin/master branch. Then compare the local master branch with the origin/master branch; Finally, merge. The above process can be done in a clearer way:


git fetch origin master:tmp
git diff tmp 
git merge tmp

Get the latest version remotely to the local tmp branch and then compare merges

2. git pull: equivalent to getting the latest version from remote and merge to local


git pull origin master

The above command is actually equivalent to git fetch and git merge. In practice, git fetch is more secure. Because before merge, we can see the updates and then decide whether or not the merge ends.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: