Plurrrr

Sun 25 Jun 2023

Completely purge files from a git repository

I have occasionally ended up with files I did not want in my git repositories. These can both take up a lot of space, and contain sensitive data that we just want to remove (such as MySQL dumps, deploy keys etc).

Git keeps a history of all files, so just deleting the file doesn’t “make it go away”. The only way to completely remove the file is to scan through all history, removing all references to (and history of) those files, and finally pruning the git repo (physically removing references to what we just deleted). Finally you have to force-push the repo changes back to the remote, overwriting the remote.

Source: Completely purge files from a git repository (including history), an article by Ralph Slooten.