1

I have a very old and huge GIT repo. A long time ago a branch A was created that has been acting as a main development branch since its creation. Other branches were created to implement features - always taking branch A as a root and merged back into the branch A.

What I would like to do is to start a new GIT repository. The new repository would take the creation of the branch A as its beginning (the beginning of its history). Thus I would like to abandon the previous history.

I am not a GIT beginner but since this is something which is not a standard GIT operation I would like to ask you guys for any advice, ideas, useful links on how I can achieve what I have just described.

To keep my question short: How to start a new repo from a branch without losing a history of that branch and its child branches?

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • Have you looked at http://stackoverflow.com/questions/1778088/how-to-clone-a-single-branch-in-git ? – ptyx May 02 '13 at 18:25
  • It's not totally clear if you want to 1) find the first commit that was called "A", and create a content-identical commit with no ancestors, or 2) just get rid of current branches (i.e. refs) that are not relevant to the current branch A. – gcbenison May 02 '13 at 21:51

1 Answers1

1

For each branch you want to do it, create a new branch with shorter history. Branch A is the most important one. Use git checkout --orphan new_A <branching_point_SHA> to create a new branch that has no history beyond the branching point. Then delete the old A, and use git branch -m to rename new_A to A per se. Repeat for all the relevant branches. Delete all the irrelevant branches, well, because they are irrelevant and useless.

Delete all the tags that are older than the branching point. It's clear that you don't need those.

Now you should have no references to the older part of the history and you can clean it up with git gc.

Since you are not a Git beginner, you obviously must understand that it will recalculate all the commit hashes etc. Play safe.

Tadeusz A. Kadłubowski
  • 8,047
  • 1
  • 30
  • 37