bashbeginner
Git Clone Specific Branch
Clone a specific branch from a remote repository without fetching all branches and history.
bashPress ⌘/Ctrl + Shift + C to copy
# 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.
bashbeginner
Rename Git Branch (Local and Remote)
Commands to rename a local and remote Git branch including updating tracking references.
Best for: Fixing branch naming convention mistakes
#git#branch
bashbeginner
Delete Remote Git Branch
Commands to delete local and remote branches, prune stale references, and clean up merged branches.
Best for: Cleaning up after merged pull requests
#git#branch
bashintermediate
Git Hooks Pre Commit
Git workflow: git-hooks-pre-commit
Best for: version control
#git#version-control
bashadvanced
Git Hooks Post Commit
Git workflow: git-hooks-post-commit
Best for: version control
#git#version-control