| name | gitleaks |
| description | Auth/lab ref: Gitleaks secret scanning; repo/directory/stdin checks, regex+entropy rules, pre-commit/CI evidence, remediation workflow. |
| license | MIT |
| compatibility | Linux / macOS / Windows. |
| metadata | {"author":"AeonDave","version":"1.0"} |
gitleaks
Fast git secrets scanner — API keys, tokens, passwords in repos and files.
Quick Start
gitleaks git /path/to/repo
gitleaks dir /path/to/project
cat file.txt | gitleaks stdin
gitleaks git . --report-path results.json
Subcommands
| Command | Target |
|---|
gitleaks git <path> | Git repository + full history |
gitleaks dir <path> | Directory or file (no git) |
gitleaks stdin | Read from stdin |
gitleaks version | Show version |
Core Flags
| Flag | Purpose |
|---|
-c, --config <file> | Path to .gitleaks.toml config |
-b, --baseline-path <file> | Baseline of known issues to ignore |
-f, --report-format <fmt> | Output format: json / csv / sarif / junit |
--report-path <file> | Save report to file |
-l, --log-level <lvl> | Log level: debug / info / warn / error |
--exit-code <n> | Exit code when leaks found (default 1) |
--no-banner | Suppress banner |
--redact | Redact secrets in output |
--max-target-megabytes <n> | Skip files larger than N MB |
--max-decode-depth <n> | Decode encoded text (base64 etc.) up to N levels |
--max-archive-depth <n> | Extract and scan archives up to N levels deep |
--no-git | Treat git repo as plain directory |
--follow-symlinks | Follow symbolic links |
--log-opts <opts> | Pass options to git log (e.g. commit ranges, branches) |
--staged | Scan staged changes (for pre-commit use) |
-v, --verbose | Show full findings |
Scanning Patterns
gitleaks git . -v
gitleaks git . --log-opts="commitA..commitB"
gitleaks git . --log-opts="-n 500"
gitleaks git . --log-opts="feature-branch"
gitleaks git . --log-opts="--since='6 months ago'"
gitleaks git . --log-opts="${CI_COMMIT_BEFORE_SHA}..${CI_COMMIT_SHA}"
gitleaks git . --staged
gitleaks dir /path/to/project -v
gitleaks git . -c .gitleaks.toml --report-path findings.json
gitleaks dir . --max-decode-depth=3 --max-archive-depth=2
Output Formats
gitleaks git . --report-format json --report-path report.json
gitleaks git . --report-format sarif --report-path report.sarif
gitleaks git . --report-format csv --report-path report.csv
gitleaks git . --report-format junit --report-path report.xml
cat report.json | jq '.[] | {rule: .RuleID, file: .File, secret: .Secret, commit: .Commit, line: .StartLine}'
cat report.json | jq -r '.[].RuleID' | sort -u
cat report.json | jq 'group_by(.RuleID) | map({rule: .[0].RuleID, count: length})'
Pre-commit Hook
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.24.2
hooks:
- id: gitleaks
gitleaks protect --staged --verbose
exit $?
SKIP=gitleaks git commit -m "message"
GitHub Actions
name: Secrets Scan
on: [push, pull_request]
jobs:
gitleaks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Common Workflows
gitleaks git . -v --report-path secrets_audit.json
gitleaks git . --staged -v
gitleaks git . --baseline-path known.json
gitleaks git . --report-path known.json
gitleaks git . --exit-code 1 --no-banner -q
echo $?
gitleaks dir ./src --report-path dir_scan.json
Resources
| File | When to load |
|---|
references/config-rules.md | Custom rule writing, .gitleaks.toml format, entropy tuning, false positive reduction |