After using git filter-branch --subdirectory-filter how do I still use old repo and reclaim git space?


April 2019


83 time


I use git filter-branch to split a subfolder out into a new repository, refer to and

My question is, according to the steps in the article, I need to create a new repo and git pull the-subdirectory-filter-result into the new repo. But is it possible I can still use old repo and reclaim the git space, i.e to make the old .git only has that subdirectory related metadata? If I can, I don't need to create a new repo, after all the old one does not have much use now.

I tried the step #5 in Paul's answer at, but it did not work. And git gc won't reclaim the git history for those un-related commits.

1 answers


You could rm the history and folders you don't want then then move the files to the root. Here Remove folder and its contents from git/GitHub's history are several options to rm folders and files.