Created
May 26, 2023 18:54
-
-
Save pedrominicz/38327485b2a5421bfe0eae28040980c4 to your computer and use it in GitHub Desktop.
Merge completely different Git repositories
This file contains 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
#!/usr/bin/env bash | |
# https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories | |
# https://stackoverflow.com/questions/2949738/git-merge-different-repositories | |
# https://git-scm.com/docs/git-filter-branch | |
# https://gist.github.com/msrose/2feacb303035d11d2d05 | |
set -e | |
repos=(comp fun karen kvm learn logic m8080 mios mm study sugar tt) | |
branches=(main master master master master main master master master main master master) | |
for repo in "${repos[@]}"; do | |
[ ! -d "$repo" ] && git clone "https://github.com/pedrominicz/$repo.git" | |
done | |
rm -rf a | |
mkdir a | |
cd a | |
git init -b main | |
for i in "${!repos[@]}"; do | |
repo="${repos[i]}" | |
branch="${branches[i]}" | |
git remote add "$repo" "../$repo" | |
git fetch "$repo" --tags | |
git switch --orphan "$repo" | |
git merge --allow-unrelated-histories --no-commit "$repo/$branch" | |
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --index-filter "git ls-files --stage |sed \"s;\t;\t$repo/;\" |GIT_INDEX_FILE=\$GIT_INDEX_FILE.new git-update-index --index-info && mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE" HEAD | |
git remote remove "$repo" | |
done | |
git switch --orphan main | |
for repo in "${repos[@]}"; do | |
git merge --allow-unrelated-histories --no-edit "$repo" | |
done | |
echo 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment