What is the difference between git fetch and git pull, and when should you use each?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
Fetch downloads remote refs and objects without changing your working tree — safe, non-destructive inspection. Pull is fetch plus merge (or rebase) in one step — convenient but can surprise you with merge commits or conflicts. Fetch first when you want to review before integrating; pull when you are confident the fast-forward is clean.
Detailed explanation
git fetch origin brings down the remote branch pointers and the objects they need, updating origin/main etc., but leaves main and your work untouched — you can git log origin/main and diff before deciding. git pull is shorthand for git fetch followed by git merge (or git rebase if pull.rebase is set), which immediately alters your current branch and working tree. The convenience trade-off: a plain pull on a diverged branch creates a merge commit you might not want; a rebase-mode pull can replay your local commits and surprise you mid-demo. Pragmatic split: fetch then merge or rebase explicitly when collaborating (you control the integration point); pull on clean tracking branches when you just want to sync. Configure pull.rebase = true if your team avoids merge commits, or pull.ff = only to block accidental merge commits.
Example
# Review before integrating:
git fetch origin
git log --oneline main..origin/main
git diff main origin/main
git merge origin/main
# Safe sync on a clean tracking branch:
git checkout main
git pull --ff-onlyInterview tip
Distinguish the two in one sentence, then give the inspect-then-integrate workflow. Naming pull.ff = only or pull.rebase config shows you have tuned this, not just read it.
Common mistakes
- Treating pull as the only way to get updates and never fetching.
- Running pull on a diverged branch and being surprised by a merge commit.
- Not setting pull.rebase or pull.ff and getting inconsistent behavior across machines.