DEV Community

Chukwuamaka Osuji
Chukwuamaka Osuji

Posted on

Cloning a Particular Branch of a Git Repository

Alt Text

Using git from the command line is something I have always wished I was good at. When I see how wonderfully well-experienced people use git from the command line, I marvel and am pushed to continue striving to attain an appreciable level of expertise in this art. Thus, whenever I use git, I try as much as possible to do so from the command line, although the lack of consistency has been a problem.

Recently, I released a second version of the miniature electronic voting application which I developed. Before I committed the codebase for the second version to the GitHub repository, I was not so sure how to go about it because there was a huge difference between the technologies used for the first and the second versions, and as such I could not add the second version as a release, because it required a separate README file. Eventually, I decided to move the first version to a new branch and commit the second and most recent version to the master branch so that I could write separate READMEs for them.

While drafting the README, I figured that less experienced command line users might find it difficult to clone a specific version (branch) of the app (repository) with the conventional git clone URL command. After a little research, I discovered a way to do this, which is a little tweak from the conventional command; git clone -b branchname URL gets the work done. So, if the name of the branch I want to clone is v1.0 and the URL to clone the repository is https://github.com/Chukwuamaka/ballotpal.git, I would do _git clone -b v1.0 https://github.com/Chukwuamaka/ballotpal.git.

If you just found out, welcome to the club!

Top comments (0)