Block it before the commit
A pre-commit hook runs a secret scanner such as gitleaks on the files being committed. If it finds something that looks like a key, the commit is refused and the developer sees which line caused it.
Run the same scanner in your deployment pipeline as well, because a hook on one laptop can be skipped.
Check what is already there
Scan the whole history once, not just the latest version. Keys removed months ago are still readable to anyone with access to the repository.
When a key has leaked
- Revoke or rotate the key first. This is the step that actually protects you.
- Check the provider's logs for use you do not recognise.
- Move the new key into a secrets store or environment variable.
- Rewrite the history only if the repository is public or widely shared.
See it in action
Our Security page shows an example log of a commit being blocked for a leaked key.