Permanently Remove Any Record of a File From git

A co-worker and I needed to remove all instances of a binary blob from one of our git repos a while back. This was a lot harder than I thought it should have been, in my opinion. However, distributed version control is not really designed to easily allow folks to delete every instance of a file. But, if you ever run into a case where you do need to expunge a file in git here is how we did it. This would work to remove a file from any cloud, service, or local git repository.

Get a new clone of the repo (in scratch/temp space)


Detach it from the remote origin

git remote rm origin

Remove the file and rewrite history

git filter-branch --index-filter 'git rm --cached --ignore-unmatch FILENAME' HEAD

Remove garbage and lingering files

git reflog expire --expire=now --all && git gc --prune=now --aggressive


Replace the centralized repo (aka REPO LOCATION) and any copies (cloud or otherwise) others might be using. Everyone should re-clone the newly replaced repo.

Your subscription could not be saved. Please try again.
Your subscription has been successful.

Subscribe to DevOps'ish!

DevOps, Cloud Native, Open Source, industry news, and the ‘ish between assembled by open source professional, DevOps leader, and Cloud Native Computing Foundation (CNCF) Ambassador Chris Short.

We use Sendinblue as our marketing platform. By Clicking below to submit this form, you acknowledge that the information you provided will be transferred to Sendinblue for processing in accordance with their terms of use


There are several guides and HOWTOs that we stumbled across to do this; those might work better for your use case (Google is your friend). But, this five step process worked very well for us.

git  remove  scm  vcs  repo  cloud