Tutorials Git & Version Control How Do I Clone a Specific Git Branch?

How Do I Clone a Specific Git Branch?

The git clone is a command-line utility that is used to make a local copy of a remote repository. It accesses the repository through a remote URL. Usually, the original repository is located on a remote server, often from a Git service like GitHub, Bitbucket, or GitLab.

To clone a repository
git clone <remote_repo>

The above command fetches all the branches and checking out one (default master). That may, for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch. And whenever you want to edit your front page, you may end up cloning 5GB of data.

To clone a specific branch from repository

With Git 1.7.10 and later, add –single-branch to prevent fetching of all branches. Example:

git clone -b feature-001-branch --single-branch <remote_repo>
Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post

Git Diff – Inspecting and Comparing Changes in Git

Next Post

How to Configure Swagger2 in Spring Boot Application?

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x