Git – Clone a Specific Branch

The below shows you how to clone a specific branch in git. Here are the commands for doing this:

mkdir $BRANCH
git init
git remote add -t $BRANCH -f origin $REMOTE_REPO
git checkout $BRANCH

Now, let’s try it by using “octocat/Spoon-Knife” repository. We will clone the change-the-title branch of this repository, let’s run the following commands:

mkdir change-the-title
cd change-the-title
git init
git remote add -t change-the-title -f origin
git checkout change-the-title