$ git filter-branch --prune-empty --tree-filter \
'if [ -d api/client/lib ]; then mv api/client/lib client; fi; if [ -d api/types ]; then mv api/types types; fi' \
-- --all
The previous command moves api/client/lib
to client
and api/types
to types
, those are the directories that we'll extract to the new repository.
git filter-branch -f --index-filter \
'git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- client types'
--prune-empty -- --all
The previous command removes everything except the client
and types
directories.
- Create new repository with
git init
in a different directory. - Add the directory you want to extract the directories from as a remote to the new repo with
git remote add OLD_REPO ../OLD_REPO
. - Pull the branch where you extracted the directories to the new repo with
git pull OLD_REPO BRANCH
.