Purging a Sensitive File from Git History on GitHub

AZ-400 By islever Editorial Last updated

Design and implement a strategy for managing sensitive information in automation Configure and manage repositories Design and implement branching strategies for the source code

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 manage source control by using GitHub.
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.
  1. git checkout git reset -hard -pathspec data.txt
  2. git checkout git clean -d data.txt --force
  3. bfg --delete-files data.txt git push --force Correct Answer
  4. git rm data.txt git push --force
  5. git filter-repo --invert-paths --path data.txt git push origin --force --all Correct Answer
  6. git revert -edit data.txt git push -force

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

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?

They only change the working tree and index of your local clone. Every historical commit still contains the file's blob, so anyone cloning or browsing history can recover the data until history is rewritten.

Which is preferred today, BFG Repo-Cleaner or git filter-repo?

git filter-repo is the actively maintained, recommended tool for full-history rewrites across all branches. BFG is simpler and faster for the single common case of deleting one file from every revision; both require a subsequent force push.

Is force-pushing enough to remove the data from GitHub?

No. Force push replaces refs, but cached objects, forks, clones and open pull requests may retain the blob, and Git LFS objects persist until purged. Contact GitHub Support and rotate any credentials that were exposed.

More AZ-400 FAQ →

Community Votes

C
73%
E
27%

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

  1. a58817 👍 4
    C & E: https://graphite.dev/guides/how-to-delete-sensitive-data-from-git
  2. Dankho 👍 3 Answered C
    Not 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
  3. fuchsm999 👍 3 Answered E
    C and E should be selected, not only one option
  4. DevopsRock 👍 3
    C and E, BFG repo cleaner and git filter-
  5. marmila 👍 3 Answered C
    I would say C for obvious reasons
Show 8 more comments
  1. songboss 👍 3 Answered C
    c와 e 두개를 선택해야합니다
  2. Mattt 👍 2 Answered C
    C & E are correct. We need 2 options
  3. Emil_Topics 👍 2 Answered C
    BFG & Filter
  4. 8ac3742 👍 1 Answered C
    both 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
  5. BorisUK2000 👍 1
    The question states "Each correct answer presents a complete solution", we need two answers.
  6. wyvern99 👍 1
    Other answers don't remove (tracked) files from (previous) commits
  7. DevopsRock 👍 1 Answered C
    BFG Repo cleaner
  8. p2006 👍 1 Answered E
    bfg, filter

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Practice All AZ-400 Questions

Access 100 questions with complete answers and detailed explanations.

View Full AZ-400 Practice Test →

← Back to AZ-400 Study Guide