StackTips

How Do I Clone a Specific Git Branch?

nilan avtar

Written by

Nilanchala,  2 min read,  3.23K views, updated on Sept. 17, 2023

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>
nilan avtar

Nilanchala

I'm a blogger, educator and a full stack developer. Mainly focused on Java, Spring and Micro-service architecture. I love to learn, code, make and break things.

Related posts

Let’s be friends!

🙌 Stay connected with us on social media for the latest updates, exclusive content, and more. Follow us now and be part of the conversation!