views:

368

answers:

1

I have a folder in my Git repository that I'd like to move out in to its own repository. Is it possible to move the history of that folder along with the folder?

I've previously been doing just a git rm -r --cached subfolder/ and then git init on the subfolder. However, the history is not imported in to the new repository.

+9  A: 

Quoting an example from git-filter-branch(1)

To rewrite the repository to look as if foodir/ has been its project root, and discard all other history:

git filter-branch --subdirectory-filter foodir -- --all

Thus you can, e.g., turn a library subdirectory into a repository of its own. Note the -- that separates filter-branch options from revision options, and the --all to rewrite all branches and tags.

jamessan
Just make sure to run this on a clone of the original repository, as it wipes the rest of the repo.
bobDevil
Amazing! I couldn't understand that option without a working example. Thanks!
sirlancelot
Also, thanks to @bobDevil for the heads up. I pushed all my changes to my remote /before/ trying this, so I'd be safe if it wiped my repo; but it would certainly be unexpected.
sirlancelot