Handling an accidentally committed secret means treating it as compromised immediately, purging it from Git history, and rotating the credential, since simply deleting the file in a new commit leaves it visible in prior history.
A developer accidentally commits a database password in application.properties; the team runs BFG Repo-Cleaner to strip it from history, force-pushes the cleaned repository, and immediately rotates the database password since it must be assumed leaked.
java -jar bfg.jar --replace-text passwords.txt my-repo.git
git push --forceA concise interview answer is
The first thing I'd do is rotate the exposed credential immediately, since it has to be treated as compromised. Then I'd use a tool like BFG Repo-Cleaner or git filter-repo to strip it from history, force-push the cleaned repo, and have the team re-clone.
Last updated: 16 July 2026
Previous question: What strategies would you employ to review a large number of pull requests effectively?
Next question: Explain how Git hooks can enhance your workflow in a team setting.