Purging a Sensitive File from Git History on GitHub
Short answer
CE Run BFG with --delete-files or git filter-repo --invert-paths and force-push all branches to purge Data.txt from repository history.
Question
You have a file named Data.txt that contains sensitive data. A user pushes Data.txt to a repository.
You need to purge the file from the repository.
Which two commands can you use? Each correct answer presents a complete solution.
NOTE: Each correct solution is worth one point.
Key Takeaways
It tests whether you distinguish history rewriting from working-tree deletion; the trap is picking git rm or git reset, which leave the secret retrievable from old commits.
This AZ-400 question tests how to purge a sensitive file from a GitHub repository's full history. The two working solutions are BFG Repo-Cleaner (C) and git filter-repo (E), both followed by a force push.
Common mistake: Option D (git rm + force push) is the most tempting wrong choice: it removes Data.txt from the current commit, but every prior commit still contains the blob, so the sensitive data is never actually purged.
Expert Analysis
The governing principle: history rewriting, not working-tree deletion.
Because Data.txt was pushed to a remote, the sensitive data exists in every commit that ever contained it, in the repository's object database on GitHub. Purging it therefore requires rewriting history and force-pushing the rewritten refs — plain deletion only removes the file from the current tree and leaves every historical blob intact. This is documented practice for secret-removal scenarios: GitHub's own guidance and the BFG and git filter-repo tools all end in a forced push, typically followed by credential rotation and contacting GitHub Support to expire cached objects and forks.
Option C is correct: BFG Repo-Cleaner. The bfg --delete-files data.txt step removes all occurrences of the file across all commits, and git push --force publishes the rewritten history. BFG is explicitly the quick, common choice for deleting a single file from every revision.
Option E is correct: git filter-repo. --invert-paths --path data.txt keeps every path except Data.txt, and git push origin --force --all republishes all branches, which is important because a file pushed by one user can be reachable from multiple branches. The community reasoning agrees: both tools "remove file and history from repo", and options that "don't remove (tracked) files from (previous) commits" are wrong.
Why the others fail. A (git reset --hard --pathspec) and B (git clean -d -f) only affect the local working tree and index — they never touch existing commits or the remote. D (git rm data.txt) deletes the file going forward but leaves it in history, so the secret stays recoverable. F (git revert) creates a new commit undoing a path; git revert does not take a file name anyway, and history is untouched. The trap is choosing the syntactically familiar git rm or git reset commands: they are working-tree operations, while the requirement is a complete purge of history.
So the two complete solutions are C and E.
Official Reference
This link opens the official vendor documentation in a new tab.
Exam Strategy
When a question says a file must be purged or removed from the repository, immediately separate working-tree operations from history rewriting: git rm, git reset --hard and git clean only touch the current tree, so they can never be the answer. Then check that the surviving option ends in a forced push (git push --force or --force --all), since the rewritten refs must overwrite the remote. Expect this pattern to appear as a two-answer selection naming BFG Repo-Cleaner and git filter-repo, and remember that real remediation also requires rotating any exposed credentials.
Frequently Asked Questions
Why don't git rm and git reset --hard purge the sensitive file?
Which is preferred today, BFG Repo-Cleaner or git filter-repo?
Is force-pushing enough to remove the data from GitHub?
Community Votes
73% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 13 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 13
-
a58817 👍 4C & E: https://graphite.dev/guides/how-to-delete-sensitive-data-from-git
-
Dankho 👍 3 Answered CNot two options, two commands, and each options has two commands. Because it's a simple delete and doesn't require "Complex history rewrites", I'm going with BFG
-
fuchsm999 👍 3 Answered EC and E should be selected, not only one option
-
DevopsRock 👍 3C and E, BFG repo cleaner and git filter-
-
marmila 👍 3 Answered CI would say C for obvious reasons
Show 8 more comments
-
songboss 👍 3 Answered Cc와 e 두개를 선택해야합니다
-
Mattt 👍 2 Answered CC & E are correct. We need 2 options
-
Emil_Topics 👍 2 Answered CBFG & Filter
-
8ac3742 👍 1 Answered Cboth C and E okey, both BFG(Big Fuck Gun) and git filter-repo can remove file and history from repo. git push --force will push active branch, and git push --force --all will push all branch
-
BorisUK2000 👍 1The question states "Each correct answer presents a complete solution", we need two answers.
-
wyvern99 👍 1Other answers don't remove (tracked) files from (previous) commits
-
DevopsRock 👍 1 Answered CBFG Repo cleaner
-
p2006 👍 1 Answered Ebfg, filter
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All AZ-400 Questions
Access 100 questions with complete answers and detailed explanations.
View Full AZ-400 Practice Test →