Skip to content

Instantly share code, notes, and snippets.

@mpg
Created June 29, 2009 16:56
Show Gist options
  • Save mpg/137698 to your computer and use it in GitHub Desktop.
Save mpg/137698 to your computer and use it in GitHub Desktop.
Split a git repo in multiple repositories, one per top-level directory.
#!/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 <http://gist.github.com/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment