How do you merge multiple repos into a monorepo with history preserved?
AdvancedProductionMonorepos, large files and repository performance
Answer
Rewrite each repo into a subdirectory with git filter-repo --to-subdirectory-filter, then fetch each into the target and merge with --allow-unrelated-histories. Tags must be renamed with a prefix to avoid collisions. Open PRs need to be re-created, so schedule a cut-over window.
git filter-repo --to-subdirectory-filter services/api
git remote add api ../api && git fetch api --tags
git merge api/main --allow-unrelated-histories
More on Monorepos, large files and repository performance
What are the main trade-offs of a monorepo?IntermediateHow do you make CI efficient in a monorepo?AdvancedHow do you onboard developers to a very large repo without a 30-minute clone?IntermediateWhat does Scalar do and when do you recommend it?Advanced`git status` takes 20 seconds in a big working tree. How do you fix it?AdvancedWhen should a team adopt Git LFS and when should it avoid it?Intermediate