`git pull` and `git fetch`, a subtle difference

404answernotfound

404answernotfound

Posted on March 9, 2022

`git pull` and `git fetch`, a subtle difference

Let's start with a primer on both commands

How would you evaluate the usage of those commands if you were tasked to do some commits in a team?

Which of those commands is more destructive than the other?

Read on to discover and if you enjoyed this article, leave a like or a unicorn or whatever makes you happier and it will surely make me happy aswell!

Also, you can find similar blogposts in my main blog 404answernotfound.eu where I write about technology, innovation, programming and most importantly, memes.

Git pull and star wars

git pull

In it's simplest usage, git pull just wants you to be happy and up-to-date with whatever changes occurred to the remote repository. Any changes, anything at all will be pulled from the remote repo and automatically merged into your cloned local repository.

See where I'm getting at? It can be problematic, especially the automatic part.

git fetch

To make sure that we are up-to-date with remote changes but without the fear of destroying the subtle existence of our local changes we can do git fetch which will (you guessed it!) fetch any commits that were done remotely and do not exist on your local repo, keeping you repo up-to-date without merging the new changes with your current branch, making it safer to update without worrying too much about disruption brought by merging conflicts and so on.

The difference between pull and fetch

So, what's the big time difference between those two commands? Usage and timing.

git pull or git fetch

git pull actually does a git fetch followed by a git merge, so, if you just want to keep your repository updated while working on your own local commits, make sure you do a lot of git fetch(es) to avoid changes in your refs/heads (where you are working) but still keeping your refs/remotes up-to-date.

Goodbyes

I hope you enjoyed this content and found it useful for your daily activities at work or for your hobbies. If you have any requests, drop a message on one of my social media accounts or open an issue/start a discussion on github, on this repository!

As always you can find me on Twitter, listen to my Podcast on Spotify and add me on LinkedIn to talk professionally (yeah, right)

💖 💪 🙅 🚩
404answernotfound
404answernotfound

Posted on March 9, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related