Gitleaks

A command-line tool that finds passwords, API keys, and tokens that have slipped into Git repositories and files.

cat gitleaks/meta.ymlChecked on 2026-10-24

Safety

Impact Local onlyStays on your machine and sends nothing out
Admin rights
Not required
Test lab
Not required

Usage

Purpose
Defense
Difficulty
Beginner
Type
Command line
Platforms
Linux / macOS / Windows / Docker

Trust

Repository
gitleaks/gitleaks
License
PermissiveMIT
GitHub
stars30,3152026-10-25
Maintenance
Actively updatedLast update 2026-10-23
Contents
  1. Introduction
  2. What Gitleaks does
  3. Try it safely on your own repository
  4. Block secrets before you commit with pre-commit
  5. Reduce false positives
  6. Cautions
  7. Read next
  8. Sources

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.

What it doesn’t doGitleaks only finds secrets. It does not remove them. You must revoke and reissue any key it finds with the service that issued it. Gitleaks only reads local files and does not send what it scans anywhere.

Try it safely on your own repository

  1. 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 gitleaks also works.

  2. Go to the folder of a repository you own.

  3. Run the following command. With --redact, the secrets themselves are masked in the output.

    gitleaks git -v --redact
  4. 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.

  1. Install pre-commit by following the official instructions.

  2. Create .pre-commit-config.yaml at the root of your repository with this content:

    repos:
      - repo: https://github.com/gitleaks/gitleaks
        rev: v8.24.2
        hooks:
          - id: gitleaks
  3. Run pre-commit autoupdate to update rev to the latest version.

  4. Run pre-commit install to 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.

Sources

  1. Official repository READMEgithub.com/gitleaks/gitleaks
  2. pre-commit hook definitions (.pre-commit-hooks.yaml)github.com/gitleaks/gitleaks/blob/master/.pre-commit-hooks.yaml
  3. Releasesgithub.com/gitleaks/gitleaks/releases
  4. Gitleaks-Action READMEgithub.com/gitleaks/gitleaks-action

Checked on 2026-10-24

Similar tools

OSV-Scanner

Impact Local only
google/osv-scanner

A 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
Actively updatedstars11,264Last update 2026-10-24
Read the OSV-Scanner review

Trivy

Impact Local only
aquasecurity/trivy

A 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
Actively updatedstars38,703Last update 2026-10-23
Read the Trivy review