Extracting a subdirectory from git as a new git repository
Some time ago (about 2 years according to the file timestamps) I created a git repository to house all of my random personal files (letters, tax returns, random notes, etc).
Unfortunately at some point in the last two years I started to add in assorted other bits that really didn't belong, just because I needed somewhere to put them. To the extent that I now have at least two complete application code bases held in this repository!
Today I finally got around to extracting them out into their own repositories. Unfortunately taking just a subdirectory from within a git repository (complete with history) doesn't seem to be quite as easy as I'd hoped.
Once gitosis was installed and I'd given myself write access to my new target repository, the process to extract the git subdirectory turned out to be...
$ cd big-old-repo $ git branch to-extract $ git filter-branch --subdirectory-filter path/to/extract to-extract $ cd .. $ mkdir tmp-new-repo $ cd tmp-new-repo $ git init $ git pull ../big-old-repo to-extract $ git remote add real-new-repo gitosis@my-server:real-new-repo.git $ git push real-new-repo master $ cd .. $ git clone gitosis@my-server:real-new-repo.git
After all of that I now have a server hosted (and a local clone) repository that has it's top level at "path/to/extract" (and that's all it contains) from my old repository, complete with all history.