TechnicalEasy Git

What is the difference between git fetch and git pull?

Asked for Frontend Developer, Backend Developer, Full-Stack Developer, Mobile Developer

Why they ask this: A basic Git question that shows whether you understand remote-tracking branches.

Answer

  • git fetch downloads new commits and branches from the remote and updates the remote-tracking branches (origin/main). It does not change your working files or your current branch.
  • git pull is git fetch followed by a merge (or a rebase, with git pull --rebase) into your current branch.
bash
git fetch origin
git log --oneline main..origin/main   # see what is new before merging
git pull --rebase origin main         # fetch and replay your commits on top

Fetching first is safer when you want to review incoming changes before integrating them.

Can you explain this in your own words?

Back to question bank