How to remove a file from Git history but keep it in a project

Sometime happen that we forget properly configure .gitignore file and keep tracking some file with sensitive data.

Firstly, remove a file from staging area:

$ git rm --cached <filename>

Then install git-filter-repo from here, e.g.:

$ pip install git-filter-repo

And finally, remove the file from all branches and all commits:

$ git filter-repo --invert-paths --path <filename>


Leave a Reply