To clone a specific Git branch, use the git clone
command with the --branch
(or -b
) option followed by the branch name and the repository URL. For example:
bash
git clone --branch <branch-name> <repository-url>
This clones only the specified branch without switching to other branches by default. If you want to clone the branch and not fetch the entire repository, you can add the --single-branch
option:
bash
git clone --branch <branch-name> --single-branch <repository-url>
This is useful for saving time and disk space if you only need one branch instead of the full repository history.