How do I clone all remote branches?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The most important thing to know is that git clone already brings down the remote branch references. You do not need a special "clone all branches" command just to know that those branches exist.
What git clone does not do is create a local working branch for every remote branch. It checks out one local branch, usually the remote default branch, and leaves the others as remote-tracking branches until you explicitly create local branches for them.
What git clone Actually Gives You
After a normal clone:
Git has already fetched the repository objects and remote-tracking branches such as:
You might see output like:
Those remote branches are already present locally as references. You do not need to clone them one by one.
Create a Local Branch When You Need One
If you want to work on a specific remote branch, create a local tracking branch for it:
Or, with older syntax:
That creates a normal local branch and sets it to track the remote branch.
Fetch New Remote Branches Later
If more branches are created on the remote after your initial clone, update your remote-tracking references with:
Then list them again:
This keeps your local knowledge of the remote repository current.
If You Really Want Local Branches for Everything
Most of the time, creating local branches for every remote branch is unnecessary clutter. But if you do need that layout, create the local branches intentionally.
For example, create one branch at a time:
That is usually clearer than mass-creating dozens of local branches you may never use.
This matters because local branches have their own reflogs, local state, and possible stale history. Remote-tracking branches are often enough until you actually begin work.
Bare Mirrors Are a Different Case
If your goal is not a working checkout but a full mirror of all refs for backup or migration, use --mirror:
A mirror clone is a bare repository. It is not meant for normal development work. It copies all refs in a way that is useful for replication, backup, and repository transfer.
So there are really two separate questions:
- normal development clone with access to all remote branches
- complete mirrored repository for administrative purposes
Do not use --mirror if you just want a normal working tree.
Why the Confusion Happens
The confusion usually comes from mixing up three concepts:
- remote branches on the server
- remote-tracking branches in your local clone
- local branches you can commit on directly
A normal clone already gives you the second category. You create the third category only when you need it.
Once that distinction is clear, the behavior of git clone, git branch -r, and git switch --track becomes much easier to understand.
Common Pitfalls
The biggest pitfall is assuming that branches are "missing" just because they do not appear in git branch. That command shows only local branches. Use git branch -r or git branch -a to see remote-tracking branches too.
Another common mistake is creating a local branch for every remote branch automatically. On large repositories, that often makes the local clone noisy and harder to manage.
People also misuse git clone --mirror for day-to-day development. A mirror clone is bare and not meant for normal editing and building.
Finally, remember to fetch again later. Cloning once does not magically keep discovering new branches forever. Use git fetch --all --prune when you want the latest remote branch state.
Summary
- '
git clonealready fetches remote branch references.' - A normal clone checks out only one local branch, not one local branch per remote branch.
- Use
git branch -rto see remote-tracking branches. - Create a local branch only when you want to work on a specific remote branch.
- Use
git clone --mirroronly when you need a full mirrored repository, not a normal working checkout.

