Search code examples
githubmonoreporepo

Break out github monorepo with history and multiple folders


We have a repo that has gotten clogged up with multiple projects in it - so it is now a monorepo.

We need to break out multiple folders together into new repos along with their history. That is:

Current repo "Monorepo" folders:

 - Foo_1
 - Foo_2
 - Bar_1
 - Bar_2
 - Bar_3
 - Stuff_to_keep_here
 - Total_junk_1
 - Total_junk_2

Each folder contains various files, with Foo being one project, Bar being another, and Total_junk being stuff that we don't want to pollute the history of any of the repos (csv files, jpgs, etc). Once the Foo and Bar projects are broken out, we don't need to keep them in Monorepo anymore.

I have watched hours of youtube videos and read numerous Q&A posts here on SO and I cannot find a single one that works for our case. They all take only 1 folder to the new repo, or they make a mirror which doesn't seem to work, or some other detail that leaves me short of my goal.

Can anyone suggest a solution that:

  1. Allows multiple folders to be broken out into a new repo that's independent of the original
  2. With history
  3. That allows the old repo to have those folders removed
  4. But also allows other history to be removed

Solution

  • After testing and evaluating multiple paths, I found 2 that could work with minimal risk to the original repo.

    1. Import Repo - https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/importing-a-repository-with-github-importer. This option works well if you want to copy the entire repo and then edit from there.

    2. Split Out Subfolder(s) - https://docs.github.com/en/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository. This one is exactly what we were looking for. It won't pull out files in the root though so it is subfolder focused. Can be used to do multiple subfolders (example in link).

    We are implementing #2 for our purposes.