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
cd $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 https://github.com/octocat/Spoon-Knife.git
git checkout change-the-title

0 0 vote
Article Rating
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x