GitLeaks is the organisation's preferred tool for scanning repositories for accidentally committed secrets.
Secret scanning should cover two separate risks:
- Secrets that already exist in repository history.
- New secrets being introduced through day-to-day development.
Teams should treat any discovered secret as compromised, revoke or rotate it, and then remove it from Git history where necessary. See Guidance for removing sensitive data from GitHub.
Use GitLeaks to enforce all of the following:
- A full repository history scan before onboarding the tool.
- Local scanning before code is pushed or merged.
- CI scanning on every pull request and on the default branch.
- Regular review of custom rules, allowlists and exclusions.
Install GitLeaks using the package manager or distribution method recommended for your platform in the official project documentation.
Typical verification commands are:
gitleaks version
gitleaks git --redact --verbose --log-opts="--all"
gitleaks dir . --redact --verboseUse gitleaks git when you need to inspect commit history. Use gitleaks dir when you want to scan the current working tree.
Teams should wire GitLeaks into local development so secrets are caught before they are pushed.
One option is to use pre-commit:
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.24.2
hooks:
- id: gitleaksIf your team uses another hook manager, apply the same principle: run GitLeaks automatically before changes leave a developer workstation.
Run GitLeaks in CI so every repository has a server-side control as well as local checks.
Example GitHub Actions step:
- name: Run GitLeaks
run: gitleaks git --redact --verbose --log-opts="--all"If you maintain a custom configuration, store it in the repository and reference it explicitly in local and CI commands so the same rules apply everywhere.
Start with the default GitLeaks ruleset and add repository-specific rules only where needed.
When adding allowlists or exclusions:
- Keep them as narrow as possible.
- Record why they are needed.
- Review them regularly and remove them when no longer justified.