Q: A developer accidentally committed an AWS access key and pushed it to the public repo. The team noticed 30 minutes later. What's the correct response, in priority order?
Treat the credential as compromised the moment it touches a public surface. Order matters:
Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "Git is an immutable directed acyclic graph (DAG); knowing commands like git reflog means you never truly lose commits. The interviewer is testing: Incident response thinking; understanding that Git history rewriting alone is not enough.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
Treat the credential as compromised the moment it touches a public surface. Order matters:
- Rotate the credential first, before anything else. In AWS IAM, deactivate the leaked key and issue a new one. Anything you do to Git history is secondary — the key was public for 30 minutes, scrapers are constant, and assume it was harvested.
- Audit usage. Check CloudTrail for any calls authenticated with that key — region, source IP, services touched. If anything looks suspicious, escalate to security.
- Remove the secret from history. A plain
git revertis not enough — the file is still in old commits in.git/objectsand visible on GitHub forever. Usegit filter-repo(the modern replacement forfilter-branch):
Remediation & Permanent Safeguards
or --replace-text to redact a string everywhere. Then force-push (this rewrites history; coordinate with the team). The order is non-negotiable: rotate → audit → scrub → prevent. Reversing 1 and 3 is a common mistake — you can't un-leak a key, but you can stop it from being valid.
git filter-repo --path secrets.env --invert-paths
- Invalidate forks and caches. GitHub caches the SHA — open a support ticket asking them to purge the leaked commit, and tell anyone with a fork to re-clone.
- Add prevention. Pre-commit hook with
gitleaksordetect-secrets, plus push protection / secret scanning enabled at the org level so this is blocked next time.
- Rotate the credential first, before anything else. In AWS IAM, deactivate the leaked key and issu...
- Audit usage. Check CloudTrail for any calls authenticated with that key — region, source IP, serv...
- Remove the secret from history. A plain git revert is not enough — the file is still in old commi...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring developer accidentally committed
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring developer accidentally committed Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring developer accidentally committed
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring developer accidentally committed Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.