Created
December 8, 2018 16:52
-
-
Save ri0t/b0310e2f7857c064c38d98d9eb525c16 to your computer and use it in GitHub Desktop.
Repo-Splitter
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
#!/bin/bash | |
# $1 = Big repo | |
# $2 = Subfolder to split | |
# $3 = New organization | |
# $4 = New reponame | |
if [ $# -ne 4 ]; then | |
echo "illegal number of parameters". | |
echo- | |
echo "Usage: split-folder.sh <big-repo> <subfolder-to-split> <new-org-name> <new-repo-name>" | |
exit | |
fi | |
cd $1 | |
echo "Splitting subtree" | |
git subtree split -P $2 -b master_$2 | |
cd .. | |
mkdir $4 | |
cd $4 | |
echo "Initializing new repo" | |
git init | |
git pull ../$1 master_$2 | |
echo "Killing old tags" | |
git tag -l | xargs git tag -d | |
git remote add github githubpriv:$3/$4 | |
cd .. | |
echo "Cleaning out old module path" | |
cd $1 | |
git rm -rf $2 | |
git commit -m "Repo split off" | |
git filter-branch -f --prune-empty --tree-filter 'rm -rf $2' HEAD | |
rm -rf .git/refs/original/ && \ | |
git reflog expire --all && \ | |
git gc --aggressive --prune=now | |
git reflog expire --all --expire-unreachable=0 | |
git repack -A -d | |
git prune | |
cd .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment