git fetch
Download remote data without changing your working directory
Practical Example
git fetch origin # fetch all branches from origin git fetch --prune # fetch and remove stale remote refs # Then: git log origin/main to see what was fetched
Command Overview & How It Works
Downloads commits, branches, and tags from a remote repository but does not modify your working directory or current branch. This makes it safer than git pull — you can review changes before integrating them. After fetching, you can inspect the remote branches with git log origin/main, diff with git diff main origin/main, or merge with git merge origin/main. Use git fetch --all to fetch from all configured remotes at once. Use git fetch --prune to remove local references to remote branches that no longer exist on the remote. Use git fetch origin to fetch all branches from origin, or git fetch origin main to fetch only the main branch. Fetching is the safest first step before deciding how to integrate remote changes.
Practical Tips
- •Fetch before you pull to review what changed first: git fetch origin, then git log origin/main.
- •Use git fetch --prune to drop local references to remote branches that no longer exist on the remote.
- •Fetching never touches your working tree — it is the safe way to see what your collaborators have pushed.