GIT: Clone only specific branches from GitHub

Viewed 2967

Is there a potential way to clone not complete repository from GitHub, but just selected branches? I've found single branch clone is possible with command:

git clone git@github/path/to/repository.git --branch my_branch_1 --single-branch

So would like to achieve something like this:

git clone git@github/path/to/repository.git --branch my_branch_1 --branch my_branch_2 --single-branch ??

It means only two of them. The issue is, that such repo is quite huge in the master branch and not needed for developers. They just need branches my_branch_1 and my_branch_2. From such branches developers should make their dev branch and later pull request on GitHub to the master.

Maybe it's possible via git remote add or something like this. But I'm not so much familiar probably with the concept of Git internally.

1 Answers

There doesn't seem to a way to clone multiple branches, but you can clone just one, then fetch the remainder like so:

git clone git@github/path/to/repository.git --branch my_branch_1 --single-branch
git fetch origin my_branch_2:my_branch_2 my_branch_3:my_branch_3
Related