A bash script to separate directories from within a large git repository into their own repository, maintaining relevant history
#!/bin/bash | |
# Enter the paths in the main repo to the subdirectories you want to extract | |
# Separate paths with spaces or newlines | |
repos=( | |
artwork | |
checklists | |
code/comingsoon | |
code/utility | |
) | |
echo "Total repos to export : ${#repos[*]}" | |
# Put the directory of the main repo here. | |
master=monolith-repo-master | |
for repo in "${repos[@]}" | |
do | |
subdir=$(basename $repo) | |
echo "${repo} => ${subdir}" | |
cp -R $master $subdir | |
cd $subdir | |
git filter-branch --prune-empty --subdirectory-filter $repo master | |
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin | |
git reflog expire --expire=now --all | |
git gc --prune=now | |
cd ../ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment