#!/bin/sh # Split a git repo in multiple repositories, one per top-level directory. # # assume there are no spaces in dir names etc. # assume the git repo is in the working directory # Manuel Pégourié-Gonnard, 2009, WTFPLv2. # This is gist #137698 REPO=$1 DOT=`pwd` DIRS=`cd $REPO && echo *` for DIR in $DIRS; do if [ -d $REPO/$DIR ]; then git clone file://$DOT/$REPO /tmp/$DIR; (cd /tmp/$DIR && git filter-branch --prune-empty --subdirectory-filter $DIR) git clone file:///tmp/$DIR $DIR; rm -rf /tmp/$DIR (cd $DIR && git remote rm origin) fi done