Git & GitHub Interview Question #34

What is the difference between git fetch and git pull?

Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Junior Beginner

Quick Interview Answer

git fetch downloads remote history and updates remote-tracking references without changing the current branch's working history. git pull fetches and then attempts to integrate the fetched changes into the current branch.

Detailed Explanation

git fetch downloads remote history and updates remote-tracking references without changing the current branch's working history. git pull fetches and then attempts to integrate the fetched changes into the current branch.

Use fetch when you want to review incoming work first. Use pull when immediate integration is appropriate and you understand whether the operation will merge or rebase.

Code Example

git fetch origin
git diff HEAD..origin/main

# Integrate later when ready
git merge origin/main