The difference between 'git pull' and 'git fetch'


What is the difference between a git pull and git fetch?

To put it plainly, a git pull performs a git fetch followed by a git merge.

git pull

We use git pull to update a local branch with its remote version. When we pull, Git will automatically attempt a merge without allowing us to review the changes.

With many branches and developers, we can run into merge conflicts quite frequently.

From the documentation for git pull:

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

git fetch

We use git fetch to tell us of any changes in the remote branch since our last pull. It does not merge the changes with our current branch but rather simply gathers the new commits from the target branch and stores them in our local repository.

This is especially useful to keep our repositories updated while working on a breaking change.

To integrate these commits into our branch, we can use git merge separately.