How would you permanently remove a sensitive file (like a leaked secret) from the entire Git history, and what tools would you use?
Last updated
Rotate the secret first: anyone who cloned already has it, so treat it as compromised.
Rewrite all history with
git filter-repo --path <file> --invert-pathsor BFG Repo-Cleaner. Avoid the slow, error-pronefilter-branch.Force-push all branches and tags and have collaborators re-clone. Expire reflogs and run
git gc, and ask the host (GitHub/GitLab) to purge cached refs.
- https://www.reddit.com/r/github/comments/1l3vh3o/how_to_completely_remove_sensitive_files_from/
- https://ujwalbudha.com.np/blogs/removing-sensitive-data-git-history
- https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository
- https://dev.to/alanwest/how-to-remove-sensitive-data-from-your-git-history-for-real-this-time-j93
- https://blogs.learningdevops.com/git-filter-repo-rewrite-git-history-3fff125ada4a
- https://github.nih.gov/advanced/owners/remove-sensitive-data
- https://medium.com/@kavithareddy.gade/removing-sensitive-data-from-a-repository-12c276cd4718
- https://www.warp.dev/terminus/remove-secret-git-history