Command guide · Remote
git fetch vs git pull: what's the difference?
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 fetch | git pull | |
|---|---|---|
| Downloads new commits | Yes | Yes |
Updates origin/main | Yes | Yes |
| Changes your local branch | No | Yes (merge or rebase) |
| Changes files in your folder | No | Yes |
| Can cause merge conflicts | No | Yes |
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 pullon your own feature branch when you just want to catch up and trust what's on the remote. - Use
git fetchwhen you want to see what changed before it lands in your branch, or before a rebase:git fetchthengit rebase origin/main. - Use
git fetch --prunenow 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.