How Do I Clone a Specific Git Branch?

nilan avtar
Nilanchala   |   #Git   |   Sep 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


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.