git filter-branch --tree-filter 'rm -f secret.txt' HEAD

Category: Git - Advanced

git filter-branch --tree-filter 'rm -f secret.txt' HEAD

Rewrite history removing a file from all commits

Rewrites the entire repository history removing a file from every commit — use for removing accidentally committed secrets.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.