How do I clone a single branch in Git?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you only care about one branch from a repository, Git can avoid fetching the other branch histories by cloning with --single-branch. This is useful for large repositories, CI jobs, or cases where you want the checkout to start focused on one branch instead of pulling everything by default.
The Standard Command
This does two things:
- checks out the
developbranch - fetches only that branch's history instead of all branches
You can use -b as a shorter form of --branch.
What Happens Without --single-branch
If you run only:
Git checks out develop, but it may still fetch the other remote branch refs and history depending on the repository and default behavior. --single-branch is what tells Git to narrow the fetch scope.
That is the flag that makes the clone more selective.
Use Shallow History Too If You Want Speed
If you only need the latest snapshot or a short recent history, combine single-branch cloning with a shallow clone.
This is especially useful in CI systems and temporary workspaces.
The tradeoff is that some history-based operations, such as deep blame or long-range diff investigation, become limited until you fetch more history.
Fetching More Later
A single-branch clone is not a permanent prison. You can still fetch other branches later.
Or even widen the remote fetch configuration if your use case changes.
So the command optimizes the starting point. It does not prevent future expansion.
Remote Branch Name Must Exist
If the named branch does not exist on the remote, the clone fails.
That is why it is worth confirming the branch name first when working with unfamiliar repositories or automation.
Single Branch Does Not Mean Detached State
After the clone, you normally land on a local branch tracking the chosen remote branch. This is not the same as checking out a raw commit into detached HEAD state.
That makes the workflow natural for normal development: pull, commit, branch, and push still work as expected on that branch.
Useful In Automation
Single-branch clones are often a good default for:
- build pipelines
- deployment jobs
- scripts that inspect one release branch
- large monorepos where extra history costs time and bandwidth
The command is simple, but the savings can be significant at scale.
Expanding Later Is Normal
If your needs change after the initial clone, you can fetch more history or other branches without recloning the repository. That makes --single-branch a bandwidth and focus optimization, not a permanent limitation on future Git operations.
Common Pitfalls
The biggest mistake is assuming -b branch-name alone always limits the fetched remote branch data. Another is combining --depth 1 with later workflows that quietly expect full history. Developers also sometimes forget that they can fetch more branches later and overcomplicate the initial clone strategy. Finally, if the branch name is wrong or only exists locally on someone else's machine, git clone cannot find it on the remote.
Summary
- Use
git clone -b branch --single-branch <url>to clone one branch selectively. - Add
--depth 1if you also want a shallow clone. - '
-bchooses the branch;--single-branchnarrows what is fetched.' - The clone can still be expanded later with additional fetches.
- This pattern is especially useful for large repositories and automation.

