OK, so you have a Git repository which has lots of code in there and you want to split a chunk out into its own repository (perhaps to make it a library). It was a while ago now, but I think this is how I did it, thanks to this howto on GitHub. (Suggestions and corrections welcome!)
First, clone the full current repo:
git clone git://myserver/original-repo
Split out the current code you want into a separate repo – in my case, the directory “directory-I-want-to-split/” (this will remove everything else, leaving just this code in the master branch). Here I’m using the subdirectory filter, but there are a number of others:
git filter-branch --prune-empty --subdirectory-filter directory-I-want-to-split/ master
Push this repo somewhere else, perhaps local (note, you need the file:/// directive):
git pull file:///home/chris/original-repo
So now that we’ve split that code out into its own repo, let’s remove it from the existing repo.
git reset --hard
git filter-branch --force --tree-filter 'rm -rf directory-I-want-to-split' HEAD
Now clone this into a new, smaller repo (can do magic with unpacking I guess, but this seems easiest way to reduce the size after removing that code).
git clone file:///home/chris/original-repo