Remove Large Files from Git History

I recently had the case of a client uploading huge tiff files (some larger than 100 MB) into Statamic image fields. Obviously, I should make this impossible in the first place.

Yet, here I was with these big files having been uploaded and auto-comitted by Statamic’s Git integration. While comitting these files worked, they couldn’t be pushed to the remote repository due to Github’s file size limits. The client had already replaced the problematic files in the backend, so the only issue was that they were still present in Git’s history, clogging up pushes and pulls.

That’s when I stumbled across git filter-repo and learned about a wonderful option called --strip-blobs-bigger-than, which does exactly what it sounds like: it removes files bigger than the threshold passed in from the repository and  rewrites Git history to make it disappear completely. Needless to say, having a backup in place is a good idea when messing around with such tools.

Here’s what I did to remove all those oversized images from the project:
git filter-repo --strip-blobs-bigger-than 50M