Git Clone Specific Branch
Clone a specific branch from a remote repository without fetching all branches and history.
# Clone a specific branch only
git clone -b develop https://github.com/user/repo.git
# Clone a specific branch with only that branch's history
git clone -b develop --single-branch https://github.com/user/repo.git
# Clone into a specific directory
git clone -b develop https://github.com/user/repo.git ./my-project
# Clone a specific branch with limited depth
git clone -b develop --depth 1 https://github.com/user/repo.git
# Clone a tag
git clone -b v1.0.0 --depth 1 https://github.com/user/repo.git
# After single-branch clone, add other branches if needed
git remote set-branches --add origin main
git fetch origin main
git checkout main
# Verify which branch is checked out
git branch -aUse Cases
- Cloning only a deployment branch for CI/CD
- Reducing clone time for large repositories
- Checking out a specific release tag
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Rename Git Branch (Local and Remote)
Commands to rename a local and remote Git branch including updating tracking references.
Delete Remote Git Branch
Commands to delete local and remote branches, prune stale references, and clean up merged branches.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.