What is git filter-branch and BFG Repo Cleaner?
Answer
Both tools rewrite Git history to remove files from ALL commits in the repository — essential when you've accidentally committed secrets, large binary files, or sensitive data. git filter-branch (built-in): git filter-branch --force --index-filter "git rm --cached --ignore-unmatch secrets.txt" --prune-empty --tag-name-filter cat -- --all — removes secrets.txt from every commit. Slow and complex. BFG Repo Cleaner (recommended): a faster, simpler Java tool specifically designed for this purpose: bfg --delete-files secrets.txt repo.git — 10-100x faster than filter-branch; bfg --strip-blobs-bigger-than 50M repo.git — remove files larger than 50MB. Git 2.22+ introduced git filter-repo (replaces filter-branch): git filter-repo --path secrets.txt --invert-paths. After rewriting history: (1) Force push all branches: git push origin --force --all; (2) Force push tags; (3) Every collaborator must reclone (their local repos have the old history). If you pushed secrets: ROTATE THEM IMMEDIATELY — even after removal from Git, GitHub caches content for some time, and anyone who already cloned has the old history.