7

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.

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
David Flegl
  • 71
  • 1
  • 4

1 Answers1

7

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
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • Thanks a lot for a quick and working answer. I've just tested and it's exactly what I was looking for. I've just set it trackable later. > git push --set-upstream origin my_branch_2 and that's fine. – David Flegl Oct 18 '19 at 08:57
  • 1
    Consider using `git remote add -t origin` to add specific branches. Otherwise the `--single-branch` parameter causes your Git to *not bother* fetching and updating the remaining remote-tracking names that you'd probably like to have. – torek Oct 18 '19 at 18:49