What is git fetch?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Git & GitHub topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
git fetch downloads commits, files, and refs from the remote repository to your local repo, but does NOT merge them into your working branch. Your local working files and branches are untouched — fetch only updates the remote tracking references (like origin/main). This makes fetch safe — you can review what's changed before integrating. Usage: git fetch — fetch from the default remote (origin); git fetch origin — explicitly fetch from origin; git fetch --all — fetch from all remotes; git fetch origin main — fetch only the main branch. After fetch, inspect changes: git log HEAD..origin/main — commits on remote not yet local; git diff HEAD origin/main — diff between local and remote. Then integrate: git merge origin/main or git rebase origin/main. Fetch vs Pull: git pull = git fetch + git merge. Best practice: use fetch to see what's coming, then consciously decide to merge or rebase. This gives you more control than git pull which automatically merges.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Git & GitHub codebase.