How do I clone a specific branch in Git?
By default, git clone checks out the repository's default branch (usually main or master). If you need a different branch checked out from the start, you can specify it directly.
For a general introduction to cloning, see our tutorial on cloning an existing repository.
Clone and check out a specific branch
git clone -b develop https://github.com/your-org/your-repo.git
This clones the full repository (all branches and history) and checks out develop as the active branch. All other branches are still available — you can switch to them with git checkout or git branch as normal.
Clone only that branch
If you do not need the other branches, add --single-branch to reduce what is downloaded:
git clone -b develop --single-branch https://github.com/your-org/your-repo.git
With --single-branch, Git fetches only the history for the specified branch. You can still fetch other branches later.
Shallow clone for speed
If you only need the latest state of a branch (common in CI/CD pipelines), add --depth 1:
git clone -b main --depth 1 https://github.com/your-org/your-repo.git
This fetches only the most recent commit, significantly reducing download size for large repositories.
Combining flags
| Goal | Command |
|---|---|
| Clone and check out a branch | git clone -b develop <url> |
| Clone only that branch | git clone -b develop --single-branch <url> |
| Shallow clone | git clone -b main --depth 1 <url> |
| Single branch + shallow | git clone -b develop --single-branch --depth 1 <url> |
Ready to streamline your Git workflow? DeployHQ deploys your code automatically whenever you push to your repository.