Live streamJoin us for "State of code review 2024" on July 18thRegister today

Understanding the differences between git pull and git fetch

Kenny DuMez
Kenny DuMez
Graphite software engineer


This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.

Both Git commands git pull and git fetch are used to update local code from a remote repository, but they serve different purposes and affect your local repository in different ways. This guide explores the differences between git pull and git fetch, explaining when to use each command and highlighting their impacts on your workflow.

git fetch is a command used to download commits, files, and refs from a remote repository into your local repo. Fetching is great for seeing what others have done without merging those changes into your own branch.

The command:

  • Updates remote-tracking branches: git fetch updates your remote-tracking branches (e.g., origin/main). These branches do not affect your local branches and provide a history of what has happened in the repository.
  • Keeps local changes safe: Fetching does not change your current branch or modify your working directory. This makes it safe to see other branches' updates without altering your local development.

To fetch the latest updates from your remote repository, run:

git fetch origin

This command fetches all the new data from the remote repository pointed to origin (the default name for your remote repository) but doesn't merge any of this new data into your working files.

Git pull, in contrast, not only fetches updates from the remote repository but also automatically merges them into your current branch.

The git pull command:

  • Combines fetch and merge: Pulling changes will fetch the latest data and then immediately attempt to merge those changes into the branch you are currently working on.
  • Can potentially lead to merge conflicts: If the changes fetched conflict with the changes you've made locally, git pull will pause and ask you to resolve those conflicts manually.

To update your current branch with the latest commits from the remote repository, use:

git pull origin main

This command fetches and merges the remote main branch into your local main branch.

  • Use git fetch when:

    • You want to see the changes made to the remote repository without merging them into your local branch.
    • You need to review or compare the changes before integrating them into your branch.
    • You are working in a sensitive or unstable branch and want to avoid unintended disruptions.
  • Use git pull when:

    • You are ready to merge remote changes and are confident it won't disrupt your local development.
    • You want to quickly synchronize your branch with the latest updates from the remote.

One effective workflow involves using git fetch to review changes before performing a git pull. This can be particularly useful in a team environment where understanding changes before merging can prevent conflicts and misunderstandings.

  1. First, fetch the changes:

    git fetch origin
  2. Compare the fetched changes to your local branch:

    git log --oneline --graph --decorate --all
  3. If you decide the changes are safe to merge, then execute a pull:

    git pull origin main

For further reading, see the official Git documentation on git pull and git fetch.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2