Git Fetch? or Git pull? 🤔

Table of contents

No heading

No headings in the article.

Is there any difference between Git Pull and Git Fetch? 🤔
Have been asking myself this question times without a number now, so I decided to make research on it and I think it will be okay if I can document it for some people who later found myself in my shoe. ( I got you covered).
Note: this article is a theory from a-z.
So sit down and lemme give you a ride!

What is Git Pull?
As defined in Atlassian: The `git pull` command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.
The `git pull` command is a combination of two other commands, `git fetch` followed by `git merge` . In the first stage of operation `git pull` will execute a `git fetch` scoped to the local branch that HEAD is pointed at. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be created and HEAD updated to point at the new commit.

What is Git Fetch?
As defined in Atlassian: The `git fetch` command download commits, files, and refs from a remote repository into your local repo. Fetching is what you do when you want to see what everybody else has been working on. It’s similar to svn update in that it lets you see how the central history has progressed, but it doesn’t force you to merge the changes into your repository.

The main difference between git pull and git fetch command is that git pull runs two commands simultaneously which is git pull itself and git merge meaning that it will download commits and files from the remote branch and and automatically update your local branch by running git merge While git fetch will download the commits and files without updating them in your local branch

Now you know what git pull and fetch are and also their differences. The question now is which one is the best among the two? Although the two work fine but notwithstanding one is better than the other.

Have concluded that git fetch is better than Git pull because It will download the remote content but not update your local repo's working state, leaving your current work intact while git pull is the more aggressive method; 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.

Thanks 🙏 for Reading till the end

I'm Ariyibi Baseet Adekunle
A frontend web developer who sometimes writes articles | I also do tech things.

Let's Connect
Twitter: ariyibibaseet_
Github: Ariyibi-Baseet
Linkedin: Ariyibi-Baseet

And don't forget to Follow, Share, and comment on your opinions
Critics are also welcomed

Thank you and let's meet in the next article

Â