How to Clone a Specific Git Branch Without Other Branches
Nelson Figueroa

Nelson Figueroa @nelsonfigueroa

About: Software Engineer

Location:
Los Angeles, California
Joined:
Sep 11, 2022

How to Clone a Specific Git Branch Without Other Branches

Publish Date: Mar 26
0 0

Cloning a Specific Branch

To clone a specific branch of a git repository without cloning all other branches, use the following command formula:

git clone --single-branch --branch <branch_name> <repo_URL.git>
Enter fullscreen mode Exit fullscreen mode

For example, if you want to clone the release-1.28 branch of the Kubernetes GitHub repository, run:

git clone --single-branch --branch release-1.28 https://github.com/kubernetes/kubernetes.git
Enter fullscreen mode Exit fullscreen mode

Cloning the Latest Commit of a Specific Branch

If you only want to clone the latest commit of a specific branch (which results in a faster and smaller cloning operation) use --depth 1. The command formula looks like this:

git clone --single-branch --branch <branch_name> --depth 1 <repo_URL.git>
Enter fullscreen mode Exit fullscreen mode

And here is another example using the release-1.28 branch of the Kubernetes GitHub repository:

git clone --single-branch --branch release-1.28 --depth 1 https://github.com/kubernetes/kubernetes.git
Enter fullscreen mode Exit fullscreen mode

References

Comments 0 total

    Add comment