Skip to content
Bugsieve
Security guides

What to do when you commit a secret

Updated October 13, 2026

If you committed an API key, token or password, assume someone has seen it. Bots scan public repositories for secrets within minutes, and private repositories are copied to laptops and CI. Rotate first, clean up second.

1. Revoke and replace

Go to the service that issued the secret and revoke it, then create a new one. Do this before anything else. Until the old one is revoked, removing it from Git does not make you safe.

2. Check for misuse

Look at the service's logs for use of the old secret from unknown places, and at billing for surprises. Rotate anything the secret could reach, such as other keys stored in the same account.

3. Remove it from the code

Move the new secret to an environment variable or a secrets manager, and delete the old value from the files. Rewriting Git history with a tool like git filter-repo is optional once the secret is revoked, and does not remove copies others have already pulled.

4. Stop it happening again

Add a pre-commit check and scan regularly. A Bugsieve scan shows the file and line of leaked keys and keeps only a masked preview.

More guides