Last active
October 17, 2018 19:27
-
-
Save jbeales/bb54bf1e91b78b837cd3f49657ca4d41 to your computer and use it in GitHub Desktop.
A bash script to separate directories from within a large git repository into their own repository, maintaining relevant history
This file contains hidden or 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 | |
# 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