Last active
June 14, 2018 00:54
-
-
Save matthewberryman/eecb82c9e43486e5325b to your computer and use it in GitHub Desktop.
Convert git repo from submodules to subtrees
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
cat .gitmodules |while read i | |
do | |
if [[ $i == \[submodule* ]]; then | |
mpath=$(echo $i | cut -d\" -f2) | |
read i; read i; | |
murl=$(echo $i|cut -d\ -f3) | |
mcommit=`eval "git submodule status ${mpath} |cut -d\ -f2"` | |
mname=$(basename $mpath) | |
echo -e "$name\t$mpath\t$murl\t$mcommit" | |
git submodule deinit $mpath | |
git rm --cached $mpath | |
rm -rf $mpath | |
git remote add $mname $murl | |
git fetch $mname | |
git branch _$mname $mcommit | |
git read-tree --prefix=$mpath/ -u _$mname | |
fi | |
done | |
git rm .gitmodules | |
git commit -m "Convert submodules." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment