Skip to content

Instantly share code, notes, and snippets.

@achauve
Last active January 11, 2024 18:01
Show Gist options
  • Save achauve/deb076b2e2eaacd83b7d28de941fe91b to your computer and use it in GitHub Desktop.
Save achauve/deb076b2e2eaacd83b7d28de941fe91b to your computer and use it in GitHub Desktop.

Multiple repos -> mono repo with history from old repos

mkdir monorepo
cd monorepo
git init .

# fetch old repos
git remote add repo_1 XXX
git fetch repo_1
git remote add repo_2 XXX
git fetch repo_2

# merge repo 1 with history
git merge repo_1/master --allow-unrelated-histories -m "add repo_1"
# move all content to subdirectory repo_1/
git ls-tree --name-only HEAD | grep -v "repo_1/" | xargs -i git mv {} repo_1/
git commit -m "move repo_1 content to repo_1/ sub directory"

# ... repeat for next repos. Just need to add multiple `grep -v repo_XXX`to move files.



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment