Interview Prep/Git & GitHub/Secrets, Signing and Security

After rotating the leaked key, you must purge it from repository history. How?

AdvancedScenarioSecrets, Signing and Security
Answer

Situation read → The key is dead, but history still shows it, and scanners and forks keep flagging it.

What I'd do →

  1. Fresh mirror clone: git clone --mirror [email protected]:org/app.git.
  2. Replace the string everywhere:
echo 'AKIAXXXXXXXXXXXXXXXX==>REMOVED' > replacements.txt
git filter-repo --replace-text replacements.txt
git push --force --mirror
  1. Ask all developers to re-clone (not pull), and close or recreate open PRs.
  2. Contact GitHub Support to purge cached views and refs/pull/* references if needed; check forks.

Why → Rewriting changes all downstream SHAs, so coordination matters. Old clones can re-introduce the secret on push.

Interview tip → BFG is an alternative, but git filter-repo is the tool Git itself recommends.

All Git & GitHub questions Roadmap: Git & GitHub

More on Secrets, Signing and Security