What is the difference between the 'git pull' and 'git fetch' commands?

Asked

Viewed 74,263 times

59

I’d like to know the difference between the commands git pull and git fetch in git versioning software.

  • 1

    Has a very good book, available in Portuguese for online consultation. Worth reading...

3 answers

74


git fetch lowers the references (refs) with names or tags from one or more repositories (if you have another remote besides the origin configured), along with the objects needed to complete them. Basically it updates local references with remote relations, but does not merge with the local branch.

git pull embeds changes from a remote repository to the local branch. It is equivalent to git fetch followed by git merge FETCH_HEAD.

References:

20

In a simple way, the git fetch searches for differences with the current branch, but does not change anything in this branch. Already git pull does the git fetch and merge the differences.

  • That’s right, corrected it.

13

git fetch downloads the last commits from the remote branch, but does not embed them with the current repository copy. These commits are only available in the branch origin\master, and the branch master remains intact.

pull amounts to doing git fetch (download the last commits) + git merge (embeds commits with the local branch)

See git pull manpage:

git pull is shorthand for git fetch Followed by git merge FETCH_HEAD.

git pull e' 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.