I have a git repo with 2 directories and multiple branches, I want to split them and create all branches
`-- Big-repo
|-- dir1
`-- dir2
Branches : b
This script does the job for me:
#!/bin/bash
set -e
if [ -z "$3" ]; then
echo "usage: $0 /full/path/to/repository path/to/splitfolder/from/repository/root new_origin"
exit
fi
repoDir=$1
folder=$2
newOrigin=$3
cd $repoDir
git checkout --detach
git branch | grep --invert-match "*" | xargs git branch -D
for remote in `git branch --remotes | grep --invert-match "\->"`
do
git checkout --track $remote
git add -vA *
git commit -vam "Changes from $remote" || true
done
git remote remove origin
git filter-branch --prune-empty --subdirectory-filter $folder -- --all
#prune old objects
rm -rf .git/refs/original/*
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune
#upload to new remote
git remote add origin $newOrigin
git push origin master
for branch in `git branch | grep -v '\*'`
do
git push origin $branch
done