Command guide · Remote

git fetch vs git pull: what's the difference?

By Git Commands · Updated · 5 min read · Checked against the official Git docs

git fetch downloads new commits from the remote but doesn't touch your work. git pull downloads them and immediately merges them into your current branch. In short: git pull = git fetch + git merge.

Side-by-side comparison

git fetchgit pull
Downloads new commitsYesYes
Updates origin/mainYesYes
Changes your local branchNoYes (merge or rebase)
Changes files in your folderNoYes
Can cause merge conflictsNoYes

How git fetch works

Git keeps a read-only copy of each remote branch, named like origin/main. git fetch updates those copies and nothing else, so you can look before you merge:

git fetch
git log main..origin/main --oneline   # commits on the remote you don't have
git diff main origin/main             # what they change

How git pull works

git pull               # fetch + merge
git pull --rebase      # fetch + rebase: no merge commit, straighter history

If you have uncommitted changes that would be overwritten, Git stops. Commit them first, or park them with git stash.

Which one should you use?

  • Use git pull on your own feature branch when you just want to catch up and trust what's on the remote.
  • Use git fetch when you want to see what changed before it lands in your branch, or before a rebase: git fetch then git rebase origin/main.
  • Use git fetch --prune now and then to clean up remote branches that were deleted on the server.

FAQ

Is git pull the same as git fetch plus git merge?

Yes, by default. git pull runs git fetch and then merges the fetched branch into yours. With --rebase (or pull.rebase=true) it rebases instead.

Is git fetch safe?

Yes. It only updates remote-tracking branches like origin/main. It never changes your files or your local branches.

Why does git pull say my branches have diverged?

Both you and the remote have new commits. Newer Git asks you to choose how to combine them: run git pull --rebase or git pull --no-rebase, or set pull.rebase once in your config.