Clone a specific branch
suggest changeTo clone a specific branch of a repository, type --branch <branch name> before the repository url:
git clone --branch <branch name> <url> [directory]
To use the shorthand for --branch, type -b. This command downloads the entire repository and checks out <branch name>.
To save disk space you can clone history leading only to single branch with:
git clone --branch <branch_name> --single-branch <url> [directory]
If --single-branch is not added, the history of all branches is cloned into [directory]. This can be an issue with large repositories.
To undo --single-branch later and fetch the rest of the repository:
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents