How to fetch changes without merging in Git
· Category: Git
Short answer
git fetch downloads remote commits and refs without merging them into your local branches.
Steps
- Fetch all remotes:
git fetch --all
- Fetch a specific remote:
git fetch origin
- Inspect fetched changes:
git log HEAD..origin/main
- Prune deleted remote branches:
git fetch --prune
Tips
- Fetch often to stay aware of remote changes without affecting your work.
- Compare branches after fetching:
git diff main origin/main. --prunecleans up local references to deleted remote branches.
Common issues
- Fetching does not update your working directory; merge or rebase manually.
- Large repositories may benefit from
git fetch --depthfor partial history.