Breaking Up Git Repositories
My SVN repository for SMSBarrage had a root directory structure like this:
SMSBarrage/
+-trunk/
+-Android\
+-Blackberry\
+-iPhone\
+-WindowsMoblie\
After importing this structure into a Git repository I realized that I wanted to break it up into multiple repositories. I had already deleted the SMSBarrage/ folder from the SVN and I didn’t want to deal with rolling back the commit. Luckily git has a very impressive command toolkit which enabled me to make this transition without losing any code, history, or even tags.
First, I cloned the repository four times into separate folders:
projects/
+-smsbarrage-android\
+-Android\
+-Blackberry\
+-iPhone\
+-WindowsMoblie\
+-smsbarrage-blackberry\
+-...
+-smsbarrage-iphone\
+-...
+-smsbarrage-windowsmobile\
+-...
Then in each root folder execute the following to make all the content of the child folder (including revision history) the new HEAD.
$ git filter-branch --subdirectory-filter Android/ -- --all
(Change Android/ to the associated folder.)
Finally, change the remote repository URL for each and push the new master.
$ git remote rm origin $ git remote add origin git@github.com:JakeWharton/smsbarrage-android.git $ git push origin master
(Change smsbarrage-android to the associated remote repository.)
Now all you have to do is delete the initial git repository and you’ll be left with multiple individual repositories for each sub-folder. Each one contains history that was only specific to its sub-folder from the original repository.
History yes – bit it appears you lose the remote svn branches – that’s assuming you want them.
February 1st, 2010 at 12:06 am