Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git pull vs fetch: what is the difference?

Two commands to retrieve remote code, but very different behavior. This page explains when to use git pull and when to prefer git fetch.

The difference at a glance

git fetch

Downloads new commits from the remote repository without modifying your local branch. It's like looking at updates before integrating them.

Formula: fetch = download

git pull

Downloads new commits and merges them automatically into your local branch. It's a shortcut: fetch + merge in one command.

Formula: pull = fetch + merge

In practice in the terminal

Here is how fetch and pull behave concretely.

git fetch (cautious)

git pull (direct)

When to use one or the other

Use git fetch when:

You want to see the changes before integrating them

You're working on a complex branch and want to avoid surprises

You want to compare your local changes with the remote

You want to choose between merge or rebase after seeing the changes

Use git pull when:

You're on a main branch with no local work in progress

You simply want to get up to date quickly

You know there won't be conflicts with your work

You prefer speed over caution

Advanced tip

The best option: git pull --rebase

Many experienced developers prefer git pull --rebase. This variant does a fetch then a rebase instead of a merge.

Advantage

Creates a linear history, without unnecessary merge commits. The log is more readable and code reviews are simpler.

How to enable it by default

git config --global pull.rebase true

All your future git pull commands will rebase automatically.

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about pull and fetch

Practice pull and fetch in a safe terminal

GitQuest investigations put you in real-world teamwork situations with remote repositories.

Start the investigations