git clone a specific branch

git clone --branch feature/login --single-branch https://github.com/user/repo.git

You only need one branch of a large repository, or you want to clone a non-default branch directly.

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