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

  1. Fetch all remotes:
git fetch --all
  1. Fetch a specific remote:
git fetch origin
  1. Inspect fetched changes:
git log HEAD..origin/main
  1. 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.
  • --prune cleans 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 --depth for partial history.