Convert a Git folder to a submodule retrospectively?

To isolate a subdirectory into its own repository, use filter-branch on a clone of the original repository:

git clone <your_project> <your_submodule>
cd <your_submodule>
git filter-branch --subdirectory-filter 'path/to/your/submodule' --prune-empty -- --all

It’s then nothing more than deleting your original directory and adding the submodule to your parent project.

Leave a Comment