Convert a git repository from submodules to subtrees

Mar 25, 2015 23:27


Git submodules and git subrees are well explained in the git-scm book.

Here's a small script that automatically converts the former to the later:

cat .gitmodules |while read ido 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 -r --cached $mpath rm -rf $mpath git remote add $mname $murl git fetch $mname git branch _$mname $mcommit git read-tree --prefix=$mpath/ -u _$mnamefidonegit rm .gitmodules
Previous post Next post
Up