Created
June 29, 2009 16:56
-
-
Save mpg/137698 to your computer and use it in GitHub Desktop.
Split a git repo in multiple repositories, one per top-level directory.
This file contains hidden or 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
#!/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