git clone a specific branch
Quick Answer
git clone --branch feature/login --single-branch https://github.com/user/repo.git
When to use this
You only need one branch of a large repository, or you want to clone a non-default branch directly.
Other causes & fixes
Clone with only the latest commit (shallow + single branch)
Fastest option for CI/CD — downloads only the tip of one branch.
git clone --depth 1 --branch feature/login --single-branch https://github.com/user/repo.git
Switch to a different branch after cloning
git fetch origin other-branch
git checkout other-branch
Clone a specific tag
Checking out a tag leaves the repository in detached HEAD state. Create a branch before committing changes.
git clone --branch v2.1.0 --single-branch https://github.com/user/repo.git
cd repo
git switch -c work-from-v2.1.0
Related