Git Pull VS Git Fetch

Kesavi Kanesalingam
2 min readMay 9, 2020

Many people are confused with git pull and git fetch. I am going to explain basic of these two commands.

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Both fetch and pull are used to download data from the remote repository. Which is appropriate, depends on your need.

Fetch

$ git fetch origin

git fetch really only downloads new data from the target branch that do not exist in your current branch and stores them in your local repository. But it does not merge them with your current branch. Fetch is great for getting a fresh view on all the things that happened in a remote repository.
Due to it’s “harmless” nature, you can rest assured: fetch will never manipulate, destroy, or screw up anything. The interesting thing about git fetch is that it will not affect to your local branch. Commits, tags, files which are updated to the remote branch, it will retrieve that from the remote branch only and make your local repository updated. But it won’t merge.

Pull

$ git pull origin master

git pull, in contrast, is used with a different goal in mind: to update your current HEAD branch with the latest changes from the remote server. git pull is the combination of git fetch and git merge . It will fetch from the remote to local and automatically merge them to your current branch.This has a couple of consequences:

  • Since “git pull” tries to merge remote changes with your local ones, a so-called “merge conflict” can occur.
  • Like for many other actions, it’s highly recommended to start a “git pull” only with a clean working copy. This means that you should not have any uncommitted local changes before you pull.

Workflow of git fetch and git pull

Comparison of git fetch and git pull

Let’s select git fetch or git pull correctly to our needs.

--

--