Synopsis
git fetch [<options>] [<remote> [<refspec>...]]
Description
The git fetch command downloads new commits, files, and refs from a remote repository into your local repo, but does NOT merge them into your working branch. After fetching, the remote-tracking refs (like origin/main) are updated, and you can inspect what's new with git log origin/main before deciding to merge or rebase.
Fetching is safe — it never modifies your working tree or current branch. Many users prefer git fetch followed by an explicit git merge or git rebase over git pull, because it gives a clear preview step. Use --all to fetch from every configured remote.
In day-to-day use, git fetch integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git fetch --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git fetch interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git fetch's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
--all | Fetch from all configured remotes. |
--prune / -p | Remove remote-tracking refs that no longer exist upstream. |
--tags | Fetch all tags from the remote. |
--depth=<n> | Limit fetched history depth (creates/maintains a shallow clone). |
--unshallow | Convert a shallow clone into a full one. |
--dry-run | Show what would be fetched. |
--force / -f | Allow non-fast-forward updates of refs. |
Examples
git fetch
# Update remote-tracking refs from origin
git fetch --all --prune
# Update from every remote and clean stale branches
git fetch upstream main
# Fetch only the main branch from upstream
git fetch --unshallow
# Backfill full history into a shallow clone
Common Mistakes
Confusing git fetch with git pull is common: fetch just downloads, while pull fetches and merges. Forgetting --prune leaves a long list of stale tracking branches over time. Configure fetch.prune = true globally to make pruning automatic.
Related Commands
git pull, git merge, git remote, git ls-remote