How to Add detect-secrets as a pre-commit Hook
A detect-secrets pre-commit hook checks staged changes against the baseline, stopping a secret before it is committed.
Add the Yelp/detect-secrets hook to .pre-commit-config.yaml with --baseline .secrets.baseline. It runs on staged files and blocks the commit on a new finding.
Steps
- Add the detect-secrets hook to
.pre-commit-config.yaml. - Pass
--baseline .secrets.baselineso known entries are ignored. - Run
pre-commit installso the hook runs on every commit.
Config
.pre-commit-config.yaml
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']Gotchas
- A local hook is bypassable with
git commit --no-verify; keep the CI scan as the real gate. - Pin
revto a released tag so hook behavior is reproducible across machines.
Related guides
How to Set Up detect-secrets With a Baseline in CIAdopt Yelp detect-secrets in CI by generating a .secrets.baseline of known findings, then failing the build o…
How to Add a Secret Scanning pre-commit HookAdd a Gitleaks pre-commit hook so secrets are caught locally on staged changes before a commit is created, sh…