Skip to content

How To Clone Specific Git Branch

How to Clone git branch. Clone a specific Git branch from remote repository. git clone specific branch. Command to clone a branch only.

Covers
Git
Versions & support
About Git →
On this page

Cloning a specific branch from a Git repository can be a useful way to work with the code, without having to clone the entire repository. Cloning a specific branch allows you to access the code, make changes, and push those changes back to the original repository.

In this article, we will walk through the steps of cloning a specific branch from a Git repository.

Clone Specific Git Branch

You can clone any remote repository with git clone command. The default clones the master (main) branch from remote. You can also specify the branch name with -b option to clone a specific branch.

git clone -b 5.8-branch https://github.com/WordPress/WordPress.git 

The above command clones the specific branch but fetches the metadata of other branches. You can view all branches details with command git branch -a.

To skip metadata of other branches use --single-branch option like:

git clone -b 5.8-branch --single-branch https://github.com/WordPress/WordPress.git 

That’s it. Switch to the newly created directory and type git branch to check the branch.

Conclusion

These are the basic steps to clone a specific branch from a Git repository. By cloning a specific branch, you can work with the code and make changes without having to clone the entire repository. This can be a useful way to collaborate with other developers or to work with a specific version of the code.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

1 Comment

  1. What’s up friends, pleasant paragraph and pleasant urging commented
    at this place, I am really enjoying by these.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top