Contents
Gitleaks looks for passwords and API keys in your code and commit history. It only reads your local repository, so you can start by running it once on your own project.
This review is for developers who keep code on GitHub or similar services. After reading it, you can do the following:
- Search your repository’s commit history for secrets
- Block secrets automatically before you commit (pre-commit)
- Ignore false positives
What Gitleaks does
Gitleaks has a command for each kind of target.
| Command | What it scans |
|---|---|
gitleaks git |
The commit history of a Git repository. It uses git log -p under the hood, so past changes are included |
gitleaks dir |
Directories and files, including folders that are not under Git |
gitleaks stdin |
Text passed on standard input |
Each finding shows the file, line, commit, and the ID of the rule that matched. You can also save results as JSON, CSV, JUnit, or SARIF.
Try it safely on your own repository
-
Download the file for your operating system from the releases page and extract it. Builds are available for Windows, macOS, and Linux. On macOS,
brew install gitleaksalso works. -
Go to the folder of a repository you own.
-
Run the following command. With
--redact, the secrets themselves are masked in the output.gitleaks git -v --redact -
Gitleaks exits with code 0 if it finds nothing and 1 if it finds leaks. Use the file name and line number to check each finding.
Always add --redact when you share your screen or when others can see the logs.
Block secrets before you commit with pre-commit
With pre-commit, Gitleaks runs on every git commit and stops commits that contain secrets.
-
Install pre-commit by following the official instructions.
-
Create
.pre-commit-config.yamlat the root of your repository with this content:repos: - repo: https://github.com/gitleaks/gitleaks rev: v8.24.2 hooks: - id: gitleaks -
Run
pre-commit autoupdateto updaterevto the latest version. -
Run
pre-commit installto enable the hook.
The hook scans only staged changes (what you added with git add). If it finds a secret, the commit fails.
There are three hook IDs: gitleaks builds and runs Gitleaks with Go, gitleaks-docker runs the official Docker image, and gitleaks-system uses the Gitleaks already installed on your machine.
To skip the hook once, put SKIP=gitleaks in front of the command, as in SKIP=gitleaks git commit ....
Reduce false positives
Values you write on purpose, such as dummy keys for tests, can trigger findings. Exclude them like this:
| Method | When to use it |
|---|---|
Add a gitleaks:allow comment to the line |
To exclude a single line |
Put the finding’s Fingerprint in a .gitleaksignore file |
To exclude a specific finding |
Pass an earlier report to --baseline-path |
To ignore old findings and see only new ones |
Write settings in .gitleaks.toml |
To add or change rules |
Cautions
- Only scan repositories you own or have permission to scan.
- A key found in an old commit stays in the history even after you delete it from the file. Revoke the key with its issuer.
- The author states in the README that Gitleaks is feature complete and future releases will be security patches only. The author’s focus has moved to its successor, Betterleaks.
- Gitleaks-Action for GitHub Actions needs a free license key for repositories owned by organization accounts. Personal accounts don’t need one. Since v2, Gitleaks-Action uses a license other than MIT.
Read next
Sources
- Official repository READMEgithub.com/gitleaks/gitleaks
- pre-commit hook definitions (.pre-commit-hooks.yaml)github.com/gitleaks/gitleaks/blob/master/.pre-commit-hooks.yaml
- Releasesgithub.com/gitleaks/gitleaks/releases
- Gitleaks-Action READMEgithub.com/gitleaks/gitleaks-action
Checked on 2026-10-24
Similar tools
OSV-Scanner
Impact Local onlyA command-line tool from Google that reads your project's dependencies and checks them against the OSV.dev vulnerability database.
- Purpose
- Defense
- Type
- Command line
- Difficulty
- Beginner
- License
- PermissiveApache-2.0
- Category
- Vulnerability scanning
Trivy
Impact Local onlyA scanner that finds vulnerabilities, misconfigurations, and embedded secrets in container images, code, and Kubernetes.
- Purpose
- Defense
- Type
- Command line
- Difficulty
- Beginner
- License
- PermissiveApache-2.0
- Category
- Vulnerability scanning / Containers and cloud