Clone a specific branch

suggest change

To 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 option for --branch, type -b. This command downloads 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 to the command, history of all branches will be cloned into [directory]. This can be issue with big repositories.


To later undo --single-branch flag and fetch the rest of repository use command:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents