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 fetchdownloads 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 pullisgit fetchfollowed by a merge (or a rebase, withgit 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 topFetching first is safer when you want to review incoming changes before integrating them.
Can you explain this in your own words?