1

My parent repository has master, development, release and feature branches. I want to create a fork with only master, development and release branch.

Is this possible with GIT. How do I achieve this?

Ankur
  • 791
  • 4
  • 15

1 Answers1

0

It kind of depends on what you mean about only wanting certain branches. Or, more to the point, on what you're hoping to gain from only having certain branches.

If it's as simple as wanting a shorter list of refs when you git branch --list --all, then Alejandro Montilla's suggestion (fork then delete branches) should work.

If the parent repo has significant size bound up in unmerged branches and you want to reclaim that space, that's a little harder. You'd have to make sure after the branches were deleted that gc cleaned it up. You can always gc a local repo, but when it's hosted on a service, they may or may not offer control over garbage collection.

Maybe you want something even more complicated... many people seem to find a history that preserves the original branch topology to be "messy" and they want to "clean it up" - much of the motivation behind various rebasing operations. This would require getting rid of not only merged branches, but the commits in (one line of) the merge's history. There's not an easy way to do this to an existing history (and if you do, any relationship between the resulting repo and the parent repo would be irrevocably lost). So if that's what you're after, you might consider re-framing the problem in terms of how to get better looking log output for the history as it exists.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • Thanks for the suggestion. To clear the problem statement a bit. I'm creating a platform and it has various on going feature development and hence those branches which would ultimately merge and close. For the distribution model (internally), people adopting the platform should be able to fork from my development repo without getting all those additional refs. So yes, I would like to help the forks being lighter than the parent repo. – Ankur Mar 30 '17 at 15:13
  • Hmm... I guess you might be able to have them make clones with the `--single-branch` option; would that meet the need? – Mark Adelsberger Mar 30 '17 at 16:36