What is git filter-branch and BFG Repo Cleaner?
Why Interviewers Ask This
This question targets practical, hands-on experience with Git & GitHub. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
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.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Git & GitHub experience.