0

I have to clone a big repository from GitHub and I don't need to get all the branches but only the master and another. I know there is the command

git clone --single-branch

but of course this command only works with one branch.

Is there a good way to go about doing this?

rafgru
  • 3
  • 1

1 Answers1

1

To clone the first branch you use

git clone --single-branch --branch master URL myclone

To get the second branch, you must change the configuration of the new repostitory:

cd myclone
git config --add remote.origin.fetch +refs/heads/foo:refs/remotes/origin/foo

This tells Git that it should also track branch foo of the remote repository. Now you do

git fetch

to get the other branch into your clone.

j6t
  • 9,150
  • 1
  • 15
  • 35