What is the difference between pull and fetch in git?

What specifically are the differences between doing a git pull and a git fetch?

 61
Author: fedorqui 'SO deja de dañar', 2015-12-02

5 answers

Of the documentation :

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

Or making a free translation:

git pull it is an abbreviation of git fetch followed by git merge FETCH_HEAD.

That is, git fetch brings the changes, but leaves them in another branch, until the git merge is done to bring them to the branch local.

 55
Author: Marcos Crispino, 2015-12-02 16:00:20

Always in a repository you have a hidden branch, which you can see by using git branch -a.

That hidden branch is origin/master.

You when using git fetch, drop the changes from the remote repository to the origin/master branch:

Git fetch origin

Now you already have the changes in origin/master, but you would have to pass them to the master branch, for that you have to use:

Git merge origin / master

From this you have the new changes to your branch master and you're done.

Here is an image I made to explain this part: enter the description of the image here

By using git pull you are combining git fetch+ git merge.

Git pull origin master

In conclusion with git pull you are saving yourself from using one more command, but I recommend that if you are just starting to use git, keep using git fetch and git merge

 58
Author: Fili Santillán, 2015-12-06 04:08:32

Actually git pull downloads the changes of the given branch and updates it against your local repository.

git fetch drop the changes of the given branch and place it in a mirror Branch which is simply a hidden branch class in which you can look at the changes of that branch, and then merge with your local branch.

The git pull is simply a git fecth + git merge. Do not use the git pull if you are actually doubtful what changes can be made. from the remote repository.

 12
Author: Andres Felipe Williams Suarez, 2019-07-08 01:41:01

When you do a git fetch, the changes from your remote repository(if any) will be downloaded to a folder called origin/master, which is a hidden folder. To include the changes to your local branch you need to merge master with origin / master.

Git pull it does all that automatically.

 3
Author: rafaelmd, 2017-04-09 22:23:24

Very short: with fetch you only query the changes that are in the repository with respect to your local copy; and with pull you lower the changes to your local. I think Sourcetree when doing pull, does a fetch first as well.

 0
Author: eugenio, 2015-12-02 15:22:42