Skip to content

Instantly share code, notes, and snippets.

@menemy
Last active October 25, 2019 17:39
Show Gist options
  • Save menemy/6c16d89e33c2af6eadd71fe57b072bd2 to your computer and use it in GitHub Desktop.
Save menemy/6c16d89e33c2af6eadd71fe57b072bd2 to your computer and use it in GitHub Desktop.
split_repo.sh script to automate git repo splitting
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied, please use split_repo.sh FOLDER_NAME_TO_SAVE_AND_MOVE FROM_REPO TO_REPO"
exit 1
fi
set -x
echo "checkout $2 to folder tmp-$1"
git clone $2 tmp-$1
cd tmp-$1
echo "Will leave source and history for $1 folder only"
git filter-branch --index-filter "git rm --cached -qr --ignore-unmatch -- . && git reset -q \$GIT_COMMIT -- $1*" --prune-empty -- --all
echo "Cleanup repo and files"
rm -rf .git/refs/original/
git reflog expire --all
git fsck --full --unreachable
git gc --aggressive --prune=now
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune
echo "Delete not needed files";
git clean -d -x -f
git reset --hard
#echo "List branches and tags, they should be moved manualy";
#git tag -l
#git branch -a
echo "Will move git origin to $3"
git remote set-url origin $3
echo "Push default branch to $3"
git push -u origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment