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.