Last active
January 25, 2019 15:43
-
-
Save jrmsamson/21f321ac5400dce6f5e2ab0b591b3a4e to your computer and use it in GitHub Desktop.
Merge multiple repos into a monorepo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Reference: http://honnef.co/posts/2016/04/merging-git-repositories/ | |
| #!/bin/bash | |
| base=baseUrl | |
| projects=(project1 project2) | |
| new_repo=agua | |
| mkdir -p "$new_repo" | |
| cd "$new_repo" | |
| git init | |
| git commit --allow-empty -m "Initial commit" | |
| for prj in "${projects[@]}"; do | |
| git remote add "$prj" "$base/$prj" | |
| git fetch "$prj" | |
| git filter-branch -f --index-filter \ | |
| 'git ls-files -s | sed "s%\t\"*%&'"$prj"'/%" | | |
| GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && | |
| mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' "$prj/master" | |
| git merge -m "Merge $prj" "$prj/master" --allow-unrelated-histories | |
| git remote rm "$prj" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment