git fetch — Downloading Without Merging
The git fetch command downloads commits, branches, and tags from a remote repository — but unlike git pull, it does not modify your working directory or current branch. This makes it the safe way to see what others have been doing.
How Fetch Works
When you run git fetch, Git contacts the remote and downloads any new commits. These commits are stored in your remote tracking branches (like origin/main), leaving your local branches untouched.
Before fetch:
local: A --- B --- C (main)
remote: A --- B --- D --- E (origin/main on server)
After fetch:
local: A --- B --- C (main) ← unchanged!
remote tracking: A --- B --- D --- E (origin/main)
Your main still points to C. The new commits D and E are available in origin/main for you to inspect.
Basic Usage
git fetch origin
This fetches all branches from the origin remote. You can also fetch a specific branch:
git fetch origin main
Inspecting Fetched Changes
After fetching, you can review the changes before deciding to merge:
git log main..origin/main --oneline
This shows commits that exist in origin/main but not in your local main. You can also see what changed:
git diff main origin/main
Fetch vs Pull
| Command | Downloads? | Merges? | Safe? |
|---|---|---|---|
git fetch | Yes | No | Very safe |
git pull | Yes | Yes | Can cause conflicts |
Think of git pull as git fetch + git merge combined. When in doubt, fetch first.
Try it!
Practice fetching and inspecting remote changes before merging:
- Check your current log:
git log --oneline - Fetch updates from origin:
git fetch origin - See what new commits arrived:
git log main..origin/main --oneline - Compare the differences:
git diff main origin/main - When you're satisfied, merge manually:
git merge origin/main - Confirm the merge:
git log --oneline
When to Use Fetch
- Before starting work — Fetch to see if there are updates, then decide how to integrate them
- When you want to review — Fetch lets you inspect changes before merging
- In scripts — Fetch is predictable because it never modifies your working tree
- When you're in the middle of something — Fetch won't disrupt your current work