Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Monorepo Merge

Assuming you have two git repositories monorepo, and my-project and want to add my-project to monorepo/projects/my-project:

cd my-project
git filter-branch --index-filter '
    git ls-files -s |
    sed "s,     ,&'"projects/my-project/"'," |
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
    mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
' HEAD
cd ../monorepo
git remote add my-project ../my-project
git fetch my-project
git checkout -b my-project my-project/master
git checkout master
git merge --allow-unrelated-histories my-project
git remote remove my-project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.