Remove unwanted blobs from your GIT history

If you have some large binary files in your GIT history, you probably want to kill/maim/destroy them to bring down the size of your repository. Here’s how.

This command removes all blobs matching the specified pattern from all commits in your history. If any commits end up empty, those commits are removed too. In my case, I wanted to remove all files matching the pattern “data/binary/big/*.dbt”.

git filter-branch --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch data/binary/big/*.dbt' --tag-name-filter cat -- --all

Now let’s do some garbage collection.


git pack-refs --all --prune
git reflog expire --expire-unreachable=now --all
git repack -A -d
git gc --aggressive --prune=now

Then push your changes to the upstream repository.

git push origin --force --all

Ted Naleid has a great write-up if you want to better understand exactly what’s going on here.
The GC commands I got from Drew Powers.