Fetch vs Pull with Git Bash

Posted by

There comes a time when you have others with access to modify or add to your repository that changes occur from the central repo and your workstation repo.  In this article, I will quickly show how to use the fetch and pull commands to update your local repo with modifications made to the central repo.

If you are looking for an example of how to do this in Visual Studio Code please go to this URL:
https://digitalthoughtdisruption.com/2020/09/09/fetch-vs-pull-with-visual-studio-code/

In my example I have modified one of the examplefiles in GitHub and added a new file called filesavedtogithub.txt.

Fetch vs Pull:

fetch

Downloads new data from a remote repository (GitHub in our examples).  However, it doesn’t integrate any of the new data into the working files. Fetch is ideal for receiving a view of the modifications that has occurred at the remote repo.

pull

Updates your current head branch with the latest modifications from the remote repo.  As part of the pull process and pulling down of new data, it also merges the new data into your current files, which can have negative outcomes.

$ git status

As you can see from the local workstation it doesn’t see any changes

$ git fetch

Gathers the updates from the remote repo

$ git status

As you can see it states that my origin/master is behind by 2 commits

Also, it indicates there are no conflicts

$ git pull

As you can see it has pulled and merged the modifications, it made the change to the existing examplefile1 and it added the filesavedtogithub.txt file

Summary:

I know this was a basic example and there were no conflicts but as you can see it is easy to fetch/pull from the remote repo.  As always, I hope y’all found this useful.

One comment

Leave a Reply