DEV Community

Cover image for What is a difference between git pull and git fetch?
Dhruv Rajkotia
Dhruv Rajkotia

Posted on

What is a difference between git pull and git fetch?

As we all know that git commands become mandatory if you are software developer. So here today I wanted to share basic understanding of the git two commands. Git pull vs fetch.

Situation:

If there were some changes recently made to your remote repository and you want to incorporate them into your local copy. then you have basically a 2 options one is git pull and another one is git fetch.

So, Now question arise what’s the difference between Git pull vs fetch.

Now let’s understand with some diagram so probably you will never forgot the difference :)

Alt Text

As per the above diagram The git fetch command downloads commits, files, and refs from a remote repository into your local repo but not update your local repo's working state. Fetching is what you do when you want to see what everybody else has been working on.

git pull is the more aggressive alternative; it will download the remote content for the active local branch and immediately execute git merge to create a merge commit for the new remote content. If you have pending changes in progress this will cause conflicts and kick-off the merge conflict resolution flow.

When we should use git fetch?

  • If you only want to see all of the current branches and changes in your remote repository without affecting your current local copy then Git fetch can get you all of the information you need.

When we should use git pull?

  • when you are ready to get latest updates from your remote repository and adding to your local copy.

That's all folks, Hope you got the idea regarding Git pull vs fetch. Please like the post if you loved it and please let me know if you have any question in comments.

Top comments (2)

Collapse
 
mhalano profile image
Marcos Alano

Simple but very interesting.

Collapse
 
dhruv_rajkotia profile image
Dhruv Rajkotia

Glad to know, you liked it. 😊