Fetch Without Merge
Understanding the difference between fetch and pull in Git
In Git, you can fetch changes from a remote repository without merging them into your current branch. This allows you to review, compare, or manipulate changes before deciding to merge or rebase.
git fetch — Fetch Without Merge
git fetch origin
This command:
- Downloads commits, branches, and tags from the remote (
origin
). - Does NOT merge them into your current branch.
- Updates remote-tracking branches (e.g.,
origin/main
) locally.
Example Workflow
# You're on 'main'
git fetch origin
# Now you can inspect the fetched changes
git log HEAD..origin/main --oneline
# Or diff them
git diff origin/main
# Or test-merge them into a temp branch
git checkout -b test-merge origin/main
Remote-Tracking Branches
After git fetch
, you’ll see updates in:
origin/main
→ latest main branch on remoteorigin/feature-x
→ latest feature branch on remote
Your local branches stay untouched.
fetch vs pull
Command | What It Does |
---|---|
git fetch | Downloads remote changes only |
git pull | Does git fetch + git merge (or rebase) |
To fetch without merging, always use:
git fetch