Git fetch Command
In this page:
What is Git Fetch?
git fetch downloads new commits, branches, and tags from a remote repository into your local database -- but critically, it never touches your working files or current branch, making it a completely safe way to check what's changed.
Example: What is Git Fetch?
git fetch origin
Fetch vs Pull
The key difference from git pull is that fetch stops after downloading: it updates your remote-tracking branches (like origin/main) but leaves your actual local branches untouched, letting you review the incoming changes with git diff or git log before merging anything.
Example: Fetch vs Pull
git fetch origin
git log origin/main
Fetching Specific Branches
git fetch origin <branch> targets just one specific branch instead of every branch on the remote, which saves time and bandwidth on large repositories where you only care about updates to one line of work.
Example: Fetching Specific Branches
git fetch origin feature-x
Pruning Obsolete Branches
When teammates delete branches on the remote, your local remote-tracking references to them can become stale; git fetch --prune cleans those up automatically, deleting local references to branches that no longer exist on the remote.
Example: Pruning Obsolete Branches
git fetch --prune
Dry Run Fetching
git fetch --dry-run shows exactly what a real fetch would download without actually downloading it -- a lightweight way to test your connection or preview incoming changes before committing to the actual transfer.
Example: Dry Run Fetching
git fetch --dry-run
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: