Fetch all branches in Git

Fetch remote-tracking branches from one or more remotes, fix a single-branch refspec, and understand what --all and --prune actually update.

Best practices
Illustration of Git branches and version history

With a normal clone, git fetch origin updates the remote-tracking branches selected by origin's fetch configuration. Use git fetch --all to fetch from multiple configured remotes. Here, all refers to remotes; it does not override a configuration that fetches only one branch.

Fetch and inspect

git fetch --all --prune
git branch -a

--prune removes stale refs within the applicable fetch mappings. git branch -a lists local branches and remote-tracking branches; fetching does not create a working local branch for every server branch.

To request all tags as well:

git fetch --all --tags

Ordinary fetching already follows relevant tags in many cases. Explicit --tags asks for all tags from the fetched remotes, which may expose name conflicts when unrelated remotes use the same tag names. Remotes configured with skipFetchAll are excluded from --all.

If some branches are still missing

Inspect the mapping:

git config --get-all remote.origin.fetch

A typical full-branch mapping is:

+refs/heads/*:refs/remotes/origin/*

A clone created with --single-branch may have a narrower one. To configure an ordinary origin remote to track all its branches:

git remote set-branches origin '*'
git fetch origin

Review custom refspecs before changing them. A shallow clone can fetch additional branch tips while still having incomplete history; branch selection and history depth are separate settings.

Decide what to integrate

Fetching normally leaves your current branch, index, and working-tree files unchanged. Review incoming history before merging:

git log --oneline HEAD..origin/main
# When you intend to integrate origin/main into the current branch:
git merge origin/main

To start work on another remote branch, create a local tracking branch with git switch --track origin/feature-x if the local name does not already exist.

FAQ

How can pruning become the default?

Use git config fetch.prune true for this repository or git config --global fetch.prune true for your account. Pruning follows refspecs; unusual mappings, especially explicit tag mappings, need care.

Is git pull --all equivalent?

No. Pull fetches and then integrates into the current branch according to the selected merge or rebase behavior. It does not update every local branch to match its remote counterpart.

Can fetch ever change local branch refs?

The normal remote-tracking configuration leaves them alone. Explicit or unusual refspecs can target other refs, so avoid treating every possible fetch command as incapable of changing them. It still does not check out incoming files into your working tree.

See git-fetch, git-remote, git-pull, and git-clone.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting