clone a branch code example

Example 1: git clone specific branch

git clone --single-branch --branch <branchname> <remote-repo>

# eg
git clone -b opencv-2.4 --single-branch https://github.com/Itseez/opencv.git

Example 2: git clone single branch

# clone only the remote primary HEAD (default: origin/master)
git clone <url> --single-branch

# as in:
git clone <url> --branch <branch> --single-branch [<folder>]

Example 3: how to git clone a branch github

git clone -b opencv-2.4 --single-branch https://github.com/Itseez/opencv.git

Example 4: clone a branch

git clone --single-branch --branch <branchname> <remote-repo>

Example 5: clone branch git

git clone <repository_url>
git branch -a
git checkout <branch_name>

Example 6: how to git clone a specific branch

# Using gh CLI

gh repo clone <username>/<reponame> -- -b <branchname>