git fetch only downloads new commits, while git pull downloads them and then integrates them into your current branch. Fetch updates your remote-tracking branches, local copies like origin/main. Fetch never changes your working files or your own branches, so it is always safe to run.
Pull integrates the upstream, the remote branch your branch tracks, and how it does that depends on your settings. By default current Git only fast-forwards, moving your branch ahead when you have no new commits of your own. A pull fails when your branch has diverged. git pull --rebase replays your commits on top instead, and git pull --no-rebase runs a merge. Set pull.rebase once to choose a default.
| Command | Updates origin/main |
Moves your branch | Can conflict |
|---|---|---|---|
git fetch |
yes | no | no |
git pull |
yes | yes | yes |
Fetching first lets you see what arrived before you decide how to combine it:
git fetch origin
git log --oneline main..origin/main # what arrived
git merge origin/main # the step git pull --no-rebase does for you
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓