Clone your repo first and the use git filter-branch to mark everything but the subdirectory that you want in your new repo to be garbage-collected.
Step 1 - To clone your local repository:
git clone /XYZ /ABC
step 2 - Let us preserve the interesting branches which we want to rewrite as well, and then remove the origin to avoid pushing there and to make sure that old commits will not be referenced by the origin:
cd /ABC
for i in branch1 br2 br3; do git branch -t $i origin/$i; done
git remote rm origin
or for all remote branches:
cd /ABC
for i in $(git branch -r | sed "s/.*origin\///"); do git branch -t $i origin/$i; done
git remote rm origin
step 3 - Then use filter-branch and reset to exclude the other files, so they can be pruned
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter ABC HEAD
step 4 - Then delete the backup reflogs so the space can be truly reclaimed (although now the operation is destructive)
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --aggressive --prune=now