Gitleaks logo

Gitleaks

Scan git history or a plain directory for committed API keys, tokens and passwords, then block new ones before the commit. Free, open source.

Overview

Gitleaks scans repository content and history for patterns that resemble credentials, tokens and other secrets. A detection is a prompt to verify exposure and rotate any real secret immediately; removing a secret from the latest commit alone may not remove it from history.

Key features

Git history scanning; configurable rules; local and CI use; machine-readable reports.

Install & first run


# Homebrew, a release binary, or Docker (distro packages lag behind)
brew install gitleaks
go install github.com/gitleaks/gitleaks/v8@latest

# Scan a repository's full commit history
gitleaks git /path/to/repo -v

# Scan a directory that is not a git repository
gitleaks dir ./src -v

# Write a JSON report you can attach to a ticket
gitleaks git . --report-format json --report-path gitleaks.json

Since 8.19 the old gitleaks detect command is deprecated: use gitleaks git or gitleaks dir. Add --redact to keep the secret values out of CI logs. Docs: https://github.com/gitleaks/gitleaks

Real-world example

Add Gitleaks to your own project’s pre-commit or CI workflow to catch accidental secret commits before release.

Common questions

Does deleting a leaked token fix the incident?

Not by itself. Revoke or rotate the credential, investigate use and then clean repository history if appropriate.

Does it need the full git history?

No - gitleaks dir scans a plain directory. Full history catches secrets that were committed and later removed, which is exactly what leaks usually are.

How do I stop false positives?

Add an allowlist to .gitleaks.toml (path, regex or commit) or an inline 'gitleaks:allow' comment. Keep the baseline file for known, accepted findings.

Can it run before the commit?

Yes: gitleaks git --pre-commit --staged, wired through pre-commit or a git hook, blocks a secret before it ever reaches history.

Semgrep

Static analysis that understands code structure, so it catches tainted input and risky patterns without a build step. Free, open source.

TruffleHog

Scan git history, filesystems and container images for secrets, then verify which keys are actually live. Free, open source.


Keep exploring: browse every assessment phase in the Pentest Hub.

Authorized testing only — only ever test systems you own or have explicit written permission to assess.