/compare/git/git-fetch-vs-git-pull
git fetch vs git pull: what is the difference?
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated
- tool
- Git
- compares
- git fetch vs git pull
git fetch downloads new commits, branches and tags from a remote and updates the remote-tracking branches (origin/main), but does not touch your local branches or your files. git pull runs git fetch and then integrates the fetched branch into your current branch, by merge (the default) or by rebase (git pull --rebase or pull.rebase=true). Fetch is always safe to run; pull changes your branch and can stop with conflicts.
See the difference
Alice pushes a commit to a shared bare repository; Bob fetches, inspects, then integrates:
git init -q --bare -b main origin.git
git clone -q origin.git alice 2>/dev/null
cd alice
printf 'v1\n' > app.txt && git add app.txt && git commit -q -m "v1" && git push -q origin main
cd .. && git clone -q origin.git bob
cd alice
printf 'v2\n' > app.txt && git commit -q -am "v2" && git push -q origin main
cd ../bob
git fetch -q
echo "--- after fetch"
git status -sb | head -1
echo "app.txt: $(cat app.txt)"
git log --oneline main..origin/main
git pull -q --ff-only
echo "--- after pull --ff-only"
git status -sb | head -1
echo "app.txt: $(cat app.txt)"Output
--- after fetch ## main...origin/main [behind 1] app.txt: v1 87d8fc1 v2 --- after pull --ff-only ## main...origin/main app.txt: v2
After fetch, Bob's branch is reported as [behind 1] and his file still says v1; the new commit exists only in origin/main. pull moves main forward and updates the file.
Side by side
| git fetch | git pull | |
|---|---|---|
| Downloads objects and updates origin/* | Yes | Yes (runs git fetch first) |
| Changes your current branch | No | Yes: merge, rebase or fast-forward |
| Changes files in the working tree | No | Yes |
| Can produce conflicts | No | Yes |
| Typical use | See what changed before integrating; update all remotes | Bring your branch up to date in one step |
A safer pull routine
git fetch
git log --oneline HEAD..origin/main # what is new upstream
git diff HEAD...origin/main # what it changes
git merge --ff-only origin/main # or: git rebase origin/mainSources
Related pages
config · gitgit config pull.rebase: merge or rebase on git pullpull.rebase decides whether git pull merges or rebases diverged branches. When it is unset, Git stops with Need to specify how to reconcile divergent branches.compare · gitgit merge vs git rebase: differences and when to use eachgit merge joins histories with a merge commit and keeps them as they happened; git rebase replays commits on a new base for a linear history with new hashes.errors · gitGit: CONFLICT (content): Automatic merge failed; fix conflicts and then commit the result.Git stops a merge when both branches changed the same lines. Edit the file between the conflict markers, git add it, then git commit; or git merge --abort.