5/15/2016 - 9:34 AM

Convert subfolder into Git submodule

Convert subfolder into Git submodule


1. Clone new repository

$ git clone --no-hardlinks original-repo copied-repo

2. Filter out the files you want to keep and remove the others

$ cd copied-repo
$ git filter-branch --subdirectory-filter sub/module/path HEAD -- --all
$ git reset --hard
$ git gc --aggressive
$ git prune
$ git remote rm origin

3. Push the new repositories to the upstream server

$ git remote add

4. Add the new repository as submodules to the original repository

$ cd original-repo
$ git rm sub/module/path
$ git commit -m "Removing the folders that are now repositories"
$ git submodule add sub/module/path
$ git submodule init
$ git submoduel update
$ git add .gitmodules sub/module/path
$ git commit -m "Added in submodules for removed folders"