git fetch
Updating remote-tracking branches without touching your work.
git fetch contacts the remote, downloads any new objects, and advances the remote-tracking branches to reflect the current state of the remote. It never touches your local branches, your index, or your working directory. It is always safe to run.
Fetch in Action
The remote has two new commits. Hit fetch and watch what updates — and what stays completely untouched.
main is at c4d5. The remote has 2 more commits you don't have yet. origin/main is stale — it hasn't been updated since your last communication with the remote.fetch vs pull
git pull is simply git fetch followed by git merge (or git rebase if configured). It updates the remote-tracking branch and immediately integrates the changes into your local branch.
Many developers prefer to fetch first so they can inspect what changed — git log origin/main, git diff main origin/main — and then consciously decide when and how to integrate.
Why Fetch is Safe
Because fetch only updates refs and downloads objects — it never modifies the working directory or moves any local branch pointer — it cannot cause conflicts, data loss, or surprise state changes.
This makes it ideal for:
- → Running on CI before builds to get the latest remote state
- → Checking if colleagues have pushed before starting work
- → Getting new branches from the remote without switching to them
- → Running in the background periodically to keep tracking refs fresh
After a Fetch — Inspecting the Difference
The most useful thing to do after fetching is understand what you got before integrating it.