Some repositories are huge. They may contain years of history, many branches for different features, and large files you do not need. Cloning everything when you only want one branch wastes time, disk space, and internet data.
Maybe you only need the stable release branch for a project, or a single feature branch a teammate asked you to test. In cases like these, Git lets you clone just that one branch, quickly and cleanly.
This guide shows the exact commands for cloning a single branch, explains the helpful depth option for even faster downloads, and covers how to fetch other branches later if your needs change.
Quick Answer
To clone only one branch, use git clone --branch branch-name --single-branch https://github.com/user/repo.git. The --branch option chooses the branch, and --single-branch stops Git from downloading all the other branches. Add --depth 1 if you also want only the latest commit for the fastest clone.
Why Clone Only One Branch?
A normal clone copies the full history of every branch by default. For a small personal project, that is fine and takes seconds. For a large company or open-source project, it can mean gigabytes of data.
Cloning one branch is useful in several real situations. You may be testing a release version without needing development branches. You may be working on a slow connection or a computer with little free space. Automated build systems also use single-branch clones to save time on every run.
There is another quiet benefit: focus. Your local copy shows only the branch you need, so branch lists stay short and there is less chance of checking out or pushing to the wrong place by mistake.
The Main Command, Step by Step
- Find the exact branch name on GitHub. Open the repository page, click the branch menu near the top left, and note the name exactly, including capital letters and slashes.
- Copy the repository URL from the green Code button. You can use the HTTPS or SSH address.
- Open your terminal and move to the folder where you keep projects, using
cd. - Run the clone command with your branch name and URL.
- Wait for the download, then move into the new folder with
cd repo-name. - Confirm your branch with
git branchandgit status.
Here is the full command with an example branch called develop:
git clone --branch develop --single-branch https://github.com/example/project.git
Shorter flag versions exist too. -b means the same as --branch, so many developers write git clone -b develop --single-branch https://github.com/example/project.git. Both forms do exactly the same job.
If Git is not set up on your machine yet, start with our step-by-step guide on installing Git on Windows 11 for beginners and then come back to this command.
Understanding Each Part of the Command
The –branch Option
--branch tells Git which branch to check out after cloning. Without --single-branch, Git would still download information about all branches, but it would open this branch first. Branch names are case-sensitive, so Feature-Login and feature-login are treated as different names.
The –single-branch Option
--single-branch limits the clone so that only the history of the chosen branch is fetched. Other remote branches are not set up for tracking. This is the part that saves space and time, so do not leave it out if a lean clone is your goal.
The Repository URL
The URL can be HTTPS, such as https://github.com/user/repo.git, or SSH, such as git@github.com:user/repo.git. Use SSH only if your keys are already set up, otherwise HTTPS is simpler for a quick clone.
The official Git documentation for the clone command lists every option with detailed explanations if you want to explore advanced cases.
Make It Even Faster with –depth 1
If you only need the latest state of the branch and not its full history, add the depth option:
git clone --branch develop --single-branch --depth 1 https://github.com/example/project.git
This is called a shallow clone. Git downloads only the most recent commit instead of every change ever made. For large projects, this can turn a ten-minute download into a few seconds.
Shallow clones suit many jobs, such as building the project, reading the code, or running the latest version. They are less suited to work that needs old history, like searching when a bug appeared. If you later need the full history, run git fetch --unshallow inside the project to download the rest.
Cloning a Branch Into a Custom Folder Name
By default, Git creates a folder named after the repository. If you want a different folder name, perhaps to keep two copies side by side, add your chosen name at the end:
git clone --branch develop --single-branch https://github.com/example/project.git my-test-copy
This is handy when you clone the same repository twice for different branches. Each copy stays separate, with its own folder, branch, and changes, so experiments never mix.
How to Get Other Branches Later
A common worry is that a single-branch clone locks you out of other branches forever. It does not. You can fetch more branches at any time when your needs grow.
- Inside your project, run
git remote set-branches --add origin branch-namefor each extra branch you want. - Then run
git fetch originto download them. - Check out the new branch with
git checkout branch-name, or view all branches withgit branch -a.
Another simple approach for a one-off look is git fetch origin branch-name followed by git checkout FETCH_HEAD. This gives you a detached view of that branch without setting up tracking.
The GitHub guide to cloning a repository also explains cloning basics and troubleshooting for beginners.
Single Branch vs Normal Clone: Which Should You Choose?
- Choose a normal clone when you will work on the project long term, switch branches often, or need full history for research and blame tools.
- Choose a single-branch clone when you need one known version, want a fast download, or are setting up an automated build.
- Choose a single-branch shallow clone when you only need the latest code to run or inspect, such as on a server or test machine.
There is no wrong choice here, only a better fit for your task. And because other branches can be fetched later, starting small rarely causes problems.
Common Mistakes to Avoid
- Guessing the branch name: Names must match exactly, including slashes like
feature/login-page. Always copy the name from GitHub. - Forgetting –single-branch: Using only
--branchopens the right branch but still downloads branch references for everything else. - Confusing a branch with a tag: The
--branchoption also accepts tag names, which leaves you in a detached HEAD state. That is fine for viewing a release, but confusing if you expect to commit. - Cloning into a folder that already has files: Git needs an empty or new folder. Clone into a fresh location to avoid errors.
- Assuming a shallow clone is broken: Missing history in a
--depth 1clone is expected behaviour, not damage. Usegit fetch --unshallowif you need history later. - Using the wrong URL type: An SSH URL fails if your keys are not set up. Switch to the HTTPS URL for a quick fix.
Conclusion
Cloning a single branch is one simple command: add --branch with the exact branch name and --single-branch to your normal clone. Add --depth 1 when you want the fastest possible download with only the latest commit.
This small skill saves real time on large projects, slow connections, and build servers. Start lean, work on the branch you actually need, and remember you can always fetch more branches later — nothing about a single-branch clone is permanent.
Frequently Asked Questions
Can I clone a specific branch without –single-branch?
Yes. git clone --branch develop https://github.com/user/repo.git checks out the develop branch, but Git still fetches references for other branches. Add --single-branch when you want the smaller, focused download.
How do I know the exact name of a branch?
Open the repository on GitHub and click the branch drop-down above the file list. Every branch name is shown there. You can also run git ls-remote --heads https://github.com/user/repo.git to list branches from the terminal.
Is a shallow clone safe for normal development?
It is safe for reading, building, and small changes, but full history tools work poorly. For long-term development where you may study history or use bisect, a normal single-branch clone without the depth limit is the better choice.
Can I push from a single-branch clone?
Yes. You can commit and push to the branch you cloned, as long as you have write access to the repository. Pushing works the same as in a full clone for that branch.
What if the branch name contains a slash?
Use the full name exactly as shown, such as feature/login-page. Git handles slashes in branch names normally, and the clone command works the same way.


Leave a Reply