Skip to content

Instantly share code, notes, and snippets.

@matthewberryman
Last active June 14, 2018 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matthewberryman/eecb82c9e43486e5325b to your computer and use it in GitHub Desktop.
Save matthewberryman/eecb82c9e43486e5325b to your computer and use it in GitHub Desktop.
Convert git repo from submodules to subtrees
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