monoreaper icon indicating copy to clipboard operation
monoreaper copied to clipboard

:seedling: Create a monorepo by merging multiple github repositories

MonoReaper

Merge multiple GitHub repositories into a monorepo while preserving commit history. Each repo will live as a subdirectory. Currently only works in Linux.

Features:

  • Merge multiple repos while keeping full history and commit hashes.
  • Specify branches of each repo to merge.
  • Migrate repos into existing monorepo.

Requirements:

  • git version 2.9+.

Usage

export MONOREPO_NAME=monorepo  # defaults to monorepo
git clone [email protected]:ksindi/monoreaper.git && cd monoreaper/
chmod +x monoreaper.sh
bash monoreaper.sh owner/repo0 owner/repo1
# you can specify another default branch via `owner/repo0/some-branch`.

The above script will create a monorepo directory with a README.md file and subdirectores repo0 and repo1. Note only the default branches of each repo will be included.

If you now want to add the monorepo to GitHub:

cd monorepo/
git remote add origin [email protected]:owner/monorepo
git push -f origin master

Merging with existing monorepos

If you already have a monorepo and want to merge other repos into it, all you have to do is include a MONOREPO_DIR env variable:

MONOREPO_DIR=path/to/my/monorepo bash monoreaper.sh owner/repo0 owner/repo1

Note that the MONOREPO_DIR must have master as default branch.

Why monorepos?