Git & GitHub Interview Question #32
What does git fetch do?
Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Junior Beginner
Quick Interview Answer
git fetch downloads new commits, branches, tags, and related references from a remote without automatically merging those changes into the currently checked-out branch.
Detailed Explanation
git fetch downloads new commits, branches, tags, and related references from a remote without automatically merging those changes into the currently checked-out branch.
This makes fetch useful when you want to inspect remote changes before integrating them. After fetching, remote-tracking references such as origin/main are updated.
Code Example
git fetch origin
git log --oneline --decorate HEAD..origin/main