What is the difference between “git pull” and “git fetch”

What is the difference between git pull and git fetch

In this article let’s understand what is the difference between “git pull” and “git fetch” commands when working with git.

Basically, git pull and git fetch are both used to sync your local repository with a remote repository’s most recent changes. However, they process the updates differently:

git pullgit fetch
It works as “bring the changes in the remote repository and also keep my own code”It works as “bring my local copy of the remote repository up to date”
It also automatically merges the changes into the current branch of your working directory.It does not automatically merge or modify your working directory.
It will updates the remote-tracking branches as well your working directoryIt will only updates the remote-tracking branches to reflect the latest state of the remote repository.
git pull is basically : git fetch + git merge.Just the git fetch
You will not be able to review the incoming changes as it will directly just merge so can disturb current state if not done wisely.git fetch is a safe operation because it doesn’t modify your local branches or working directory. It only updates the remote-tracking branches.

As you can see from the differences above it is clear that, the main difference between two of them is, git pull will take the incoming changes from remote and will automatically merge them with your local directory while git fetch will lt you identify them before and do not merge the incoming changes into local.

Hope the article helps you find the right choice.

Read more on git here.