{
 "schema_version": 1,
 "generated": "2026-11-09",
 "id": "gitleaks-gitleaks--block-secrets-with-a-pre-commit-hook",
 "repo": "gitleaks/gitleaks",
 "repo_url": "https://github.com/gitleaks/gitleaks",
 "repo_slug": "gitleaks-gitleaks",
 "title": "Stop secrets before they are committed",
 "page_title": "How to stop secrets before they are committed with Gitleaks",
 "summary": "Add Gitleaks as a pre-commit hook so a commit containing a secret fails on the developer's machine.",
 "who": "A small team that keeps finding API keys in pull requests after the fact.",
 "problem": "Catching secrets in review is too late: once pushed they are in history and must be rotated.",
 "outcome": "Commits that contain hardcoded secrets fail locally with a Detect hardcoded secrets message.",
 "steps": [
  "Install pre-commit from the pre-commit website",
  "Create .pre-commit-config.yaml at the repo root with the Gitleaks repo, a rev and the Gitleaks hook id",
  "Update to the latest version with `pre-commit autoupdate`",
  "Install the hook with `pre-commit install`",
  "Try a commit with a fake secret to confirm it fails; SKIP=Gitleaks bypasses the hook when you truly need to"
 ],
 "agent_prompt": "Set up gitleaks/gitleaks as a pre-commit hook in <repo>: write .pre-commit-config.yaml, run pre-commit autoupdate and pre-commit install, then prove it works by trying to commit a file with a fake API key. Do not commit the test file.",
 "agents": [
  "claude-code",
  "codex",
  "cursor"
 ],
 "difficulty": "Beginner",
 "time": "15 minutes",
 "basis": "readme",
 "caveat": "Anyone can skip a local hook, so pair it with the GitHub Action or a CI scan for real enforcement.",
 "category": "Security and science",
 "tags": [
  "Security and science"
 ],
 "lang": "go",
 "requirements": [
  "Homebrew, Docker, Go to build from source, or a release binary",
  "pre-commit if you want the hook",
  "Read access to the repos or folders you scan"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.9,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/gitleaks-gitleaks/block-secrets-with-a-pre-commit-hook/",
 "md": "https://dedupedai.com/use-cases/gitleaks-gitleaks/block-secrets-with-a-pre-commit-hook/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/gitleaks-gitleaks--block-secrets-with-a-pre-commit-hook.json",
 "api_version": "v1"
}
