How to Shrink/Cut a Git Repo

The best step-by-step instructions can be found on the Git SCM historical blog post "Replace Kicker" or in the Git book's chapter on "Replace".

The short summary is this:

  • Create a new branch that is at the point where you want to cut, say git branch history hash.
  • Push the history to a new repository.
  • Create a new base using git commit-tree.
  • Rebase your post-history commits onto your new base.
  • Push your new truncated master branch up to the server.
  • People can then use git replace to re-connect the history together.

The original post explains it much better with pictures.

When dealing with complex histories involving merges, this may not work well, depending on how well git rebase --onto works with --preserve-merges. You should obviously test well before proceeding.

Tags:

Branch

Git