Q4 of 40 · Git
What's the difference between `git fetch` and `git pull`?
Short answer
Short answer: git fetch downloads new commits and branch refs from the remote but doesn't change your working directory or current branch. git pull is fetch + merge (or fetch + rebase if configured). Fetch first to inspect remote changes safely; pull to integrate them. Prefer git pull --rebase to avoid noisy merge commits.
Detail
git fetch contacts the remote, downloads any new commits and branch refs, and updates your remote-tracking refs (e.g., origin/main), but leaves your working directory and local branches completely unchanged. It's a read-only operation — you can inspect what changed before deciding how to integrate.
git pull is shorthand for git fetch followed by git merge (or git rebase if pull.rebase true is configured). It modifies your working directory.
Why this matters in practice: if you run git pull while mid-way through work, Git creates a merge commit that says "Merge branch 'main' of ..." — noise in the history. The pattern most teams now prefer:
git fetch origin
git rebase origin/main # or git pull --rebase
This keeps your commits on top of the latest remote state without an extra merge commit.
// EXAMPLE
# fetch — download remote refs, don't touch working directory
git fetch origin
# See what changed on the remote without integrating yet
git log HEAD..origin/main --oneline
# Integrate cleanly with rebase (no merge commit)
git rebase origin/main
# Or do it in one step
git pull --rebase origin main
# Set rebase as the default pull strategy permanently
git config --global pull.rebase true// WHAT INTERVIEWERS LOOK FOR
// COMMON PITFALL
// Related questions