The difference between ‘git pull’ and ‘git fetch’?

Original article was published on Artificial Intelligence on Medium


The difference between ‘git pull’ and ‘git fetch’?

The question we secretly ask

Photo by Kristina Flour on Unsplash

This is a brief explanation for the difference between git pull and git fetch then merge. It’s a question that a lot of people want the answer to, being the 4th more most updated question on stackoverflow.

The reason so many people get confused is that upon first glance, they seem to do the same thing (fetching is kind of the same as pulling, right?), but, each has a distinctly different job.

git is what you would call a version control system. It tracks changes in code for software development, ensuring that there’s one central truth to code- and any changes to it are accurately recorded. It’s designed to coordinate work amongst programmers, but can be used to track any set of fils really. It’s pretty handy and a lot of people use it!

Note: In a coming article, I talk about git in a lot more detail, so I’ll be leaving out an introduction to it in this post. If you have any questions though, please leave a comment at the bottom!

In Brief:

If you want to update your local repo from the remote repo, but, you don’t want to merge any differences, then you can use:

Then after we download the updates, we can check for any differences as follows:

  • git diff master origin/master

After which, if we’re happy with any differences, then we can simply merge the differences as follows:

On the other hand, we can simply fetch and merge at the same time, where any differences would need to be solved. This can be done as follows: