Created
May 21, 2019 09:17
-
-
Save martinjlowm/e51db64795b71d7dedcc19b191340bc0 to your computer and use it in GitHub Desktop.
Migrate a repository to a mono repo
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
monofyRepo() { | |
repository=$(basename $PWD) | |
if [[ ! -d ".git" ]]; then | |
echo "! $repository is not a git repository." | |
return | |
fi | |
echo "» Monofying repository ($repository)...\n" | |
echo "» Make sure all branches are merged into master" | |
git checkout master > /dev/null 2>&1 | |
if [[ "$?" != "0" ]]; then | |
echo "! Failed to checkout master" | |
return | |
fi | |
while true; do | |
echo "» Enter the new name of the subdirectory for this project:" | |
printf "> " | |
read newName | |
if [[ "$newName" =~ ^[0-9a-zA-Z_-]+ ]]; then | |
mkdir -p "$newName" | |
break | |
else | |
echo "! The `$newName` must be a valid directory name.\n" | |
fi | |
done | |
echo "» Moving all files into $newName/" | |
ls -a1 | grep -v "^$newName" | xargs -I{} git mv {} "$newName" | |
git commit -m "Moved repository into $newName/" | |
echo "» Change directory to the monorepo and run:" | |
echo " git remote add $newName $PWD" | |
echo " git fetch $newName" | |
echo " git merge -m \"[Mono] Added $newName\" --allow-unrelated-histories $newName/master" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment