What is the difference between git fetch and git pull?

git fetch downloads remote changes without applying them; git pull fetches and immediately merges (or rebases) into your current branch.

GitVersion Control

Overview

Both commands download changes from a remote repository, but `git fetch` stops there while `git pull` goes further and integrates those changes into your working branch. Think of `fetch` as a safe preview and `pull` as fetch + merge.

Key Points

  • •`git fetch` updates your remote-tracking branches (e.g. `origin/main`) but does NOT touch your local branch.
  • •`git pull` = `git fetch` + `git merge` (or `git rebase` with `--rebase`).
  • •After `git fetch` you can inspect changes with `git log origin/main` before deciding what to do.
  • •`git pull --rebase` replays your local commits on top of the fetched changes no merge commit.
  • •Fetching is always safe; pulling can trigger conflicts if your local branch has diverged.

Examples

Fetch then inspect before merging

bash
git fetch origin

# See what changed on the remote
git log HEAD..origin/main --oneline

# See the diff
git diff HEAD origin/main

# Decide to merge
git merge origin/main

This is the safest workflow you review before integrating.

Pull with merge (default)

bash
git pull origin main
# equivalent to:
# git fetch origin
# git merge origin/main

Pull with rebase (cleaner history)

bash
git pull --rebase origin main
# equivalent to:
# git fetch origin
# git rebase origin/main

Keeps history linear. Set as default with: git config --global pull.rebase true

Fetch all remotes and prune deleted branches

bash
git fetch --all --prune

--prune removes remote-tracking refs for branches deleted on the remote.

Pro Tip

Prefer `git fetch` + review + `git merge` in teams. Use `git pull --rebase` as your daily driver when you want linear history. Never use plain `git pull` on a shared branch without understanding if you have local commits that could create an unwanted merge commit.