Skip to content
Gitleaks

Gitleaks

Category: Secrets
License: Free (Open-Source, MIT)
Suphi Cankurt
Suphi Cankurt
+7 Years in AppSec
Updated February 12, 2026
5 min read
Key Takeaways
  • Gitleaks has 25,900 GitHub stars and is one of the most widely adopted open-source secret scanners, licensed under MIT.
  • Outputs in JSON, CSV, JUnit, and SARIF formats โ€” SARIF integrates directly with GitHub Advanced Security alerts.
  • Official GitHub Action and pre-commit hooks enable automated scanning in CI/CD pipelines and local development.
  • Scans git history, uncommitted changes, files, and directories with configurable rules and custom regex patterns.

Gitleaks is an open-source secret scanner designed to detect and prevent hardcoded secrets in git repositories. Maintained by Zach Rice and the Gitleaks community, it has over 25,900 GitHub stars and is one of the most widely adopted SAST tools for secret detection.

Gitleaks pre-commit hook blocking a git commit that contains an AWS access token โ€” showing RuleID, secret, file, and the failed hook with error message

According to the 2025 Verizon Data Breach Investigations Report, stolen credentials remain one of the top initial access vectors for breaches. Security teams pick Gitleaks for its speed, accuracy, and low false positive rate compared to entropy-only scanners.

What is Gitleaks?

Gitleaks scans git repositories, files, directories, and stdin to find exposed API keys, passwords, tokens, and other sensitive data. The tool uses regex patterns and entropy detection to identify secrets that developers accidentally commit to version control.

gitleaks detect CLI output showing two secret findings โ€” an AWS access key and a Slack webhook โ€” with commit metadata

Unlike full-featured SAST platforms, Gitleaks focuses exclusively on secret detection. This specialization makes it faster and easier to integrate into existing development workflows.

You can run it locally as a pre-commit hook, in CI/CD pipelines, or as a GitHub Action to scan pull requests automatically.

Gitleaks generates reports in multiple formats including JSON, CSV, JUnit, and SARIF. The SARIF output integrates with GitHub Advanced Security, allowing you to view findings directly in GitHub’s security tab and block pull requests that introduce secrets.

Git History Scanning
Scans entire git history or specific commits to find secrets introduced at any point in your repository’s lifetime
Flexible Reporting
Generate reports in JSON, CSV, JUnit, or SARIF formats, or create custom templates using Go text/template
CI/CD Integration
Official GitHub Action plus Docker images for easy integration with GitLab CI, Jenkins, and other automation platforms

Key features

FeatureDetails
CLI commandsgit (scan repos), dir (scan directories), stdin (pipe input)
ConfigurationTOML format (.gitleaks.toml), env vars, or --config flag
Output formatsJSON, CSV, JUnit, SARIF, custom Go templates
InstallationHomebrew, Docker (DockerHub + ghcr.io), binary releases, from source
Composite rulesPrimary + auxiliary rules with proximity constraints (v8.28.0+)
Baseline supportSkip known findings via baseline reports
LicenseMIT
GitHub Actiongitleaks/gitleaks-action@v2

Configurable detection rules

Gitleaks ships with built-in rules for common secret patterns (AWS keys, GitHub tokens, Slack webhooks, etc.). Customize rules or add your own regex patterns in a .gitleaks.toml configuration file.

The tool supports allowlists at both rule-specific and global levels to exclude false positives.

Since v8.28.0, composite rules let you combine a primary rule with auxiliary rules that must match within a specified proximity (withinLines, withinColumns). This reduces false positives for patterns that only matter when they appear near related identifiers.

Pre-commit hook protection

Install Gitleaks as a pre-commit hook to block secrets before they reach your repository. When a developer attempts to commit code containing secrets, Gitleaks stops the commit and displays the offending lines.

Skip the hook temporarily with SKIP=gitleaks git commit when needed.

GitHub Action

Gitleaks GitHub Action detecting secrets in pull requests with summary view

The official gitleaks/gitleaks-action@v2 runs on pull requests and pushes. For organization repositories, a GITLEAKS_LICENSE secret is required.

The action scans changed files and blocks merges when secrets are found.

SARIF output for GitHub integration

Export findings in SARIF format to populate GitHub’s security tab. This puts secret findings alongside CodeQL and Dependabot results in a single view.

Archive and encoding scanning

Gitleaks can scan nested archives (zip, tar, etc.) via --max-archive-depth and recursively decode encoded content with --max-decode-depth. Both default to 0 (disabled) and can be tuned based on your scanning needs.

Getting started

1
Install โ€” Run brew install gitleaks on macOS, or pull the Docker image with docker pull zricethezav/gitleaks:latest. Binary releases are available for Linux, macOS, and Windows.
2
Scan a repository โ€” Run gitleaks git -s /path/to/repo to scan git history for secrets. Use gitleaks dir -s /path/to/dir for non-git directories.
3
Set up pre-commit โ€” Add Gitleaks to .pre-commit-config.yaml with rev: v8.24.2. Developers get instant feedback before commits reach the repository.
4
Review findings โ€” Use --report-path results.json --report-format json to save findings. Upload SARIF output to GitHub Advanced Security with --report-format sarif.

Gitleaks tutorial: install and first scan

The full first-scan loop takes about three minutes on a clean macOS or Linux box.

Install. On macOS, brew install gitleaks is the lowest-friction path. On Linux or in a CI runner, grab the static binary from the GitHub releases page or pull ghcr.io/gitleaks/gitleaks if you prefer a container. The binary is self-contained โ€” no Go runtime, no system libraries.

Scan a repository. Point Gitleaks at any local clone:

gitleaks git -s /path/to/repo -v

The -v flag prints each finding inline so you can see what was caught without opening a report. To walk the entire commit graph including unreachable commits, add --all --full-history. For a one-off scan of an uncommitted working tree, gitleaks dir -s . works without a .git directory.

Add a pre-commit hook. Install pre-commit once, then add Gitleaks to .pre-commit-config.yaml:

repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.24.2
    hooks:
      - id: gitleaks

Run pre-commit install and every subsequent git commit triggers a scan against the staged diff. New secrets fail the commit before they reach the repo.

Read the report. Add --report-path results.json --report-format json for machine consumption, or --report-format sarif to upload findings into GitHub’s Security tab via the official gitleaks/gitleaks-action@v2. The SARIF route is the path most teams settle on because it puts Gitleaks findings next to CodeQL and Dependabot in one dashboard.

When to use Gitleaks

Gitleaks is the go-to choice for teams that want fast, no-frills secret scanning in git repositories. It runs offline, installs as a single binary, and integrates with GitHub Actions out of the box.

For scanning beyond git (Slack, S3, Docker images), TruffleHog covers more ground. For enterprise environments with legacy codebases, detect-secrets offers a baseline approach that avoids upfront remediation.

Three-way comparison: Gitleaks (git-focused, SARIF native) vs TruffleHog (multi-source plus credential verification) vs detect-secrets (baseline approach)
Best for
Development teams that need fast, reliable secret scanning in git repositories and CI/CD pipelines, especially those using GitHub or requiring SARIF output for security dashboards.

Gitleaks vs TruffleHog

Gitleaks and TruffleHog are the two most-used open-source secret scanners, and the right pick depends on what you are scanning and how false-positive-tolerant you are.

Speed and scope. Gitleaks is a single Go binary that runs regex and entropy detection against git history, files, and directories. TruffleHog v3 (also Go) ships 800+ detectors and scans Docker images, S3 buckets, GCS buckets, Slack workspaces, CircleCI logs, and more. If the surface is git-only, Gitleaks finishes faster on a clean repo because it skips the verification step. If the surface includes anything off-disk, TruffleHog is the only option of the two.

Verification. TruffleHog’s defining feature is live API verification โ€” when it finds an AWS key, it calls the AWS API to confirm whether that key is still active. Gitleaks does not verify; it only reports the regex match. Verification is what drives TruffleHog’s lower false-positive rate but also adds runtime cost and outbound network calls some teams cannot allow.

Pre-commit fit. Both ship pre-commit hooks. Gitleaks’s tighter scope and faster startup make it the more common pick for blocking commits in seconds; TruffleHog’s verification step adds latency that most teams disable for the pre-commit path.

For the full feature-by-feature breakdown including rule formats, license, and configuration patterns, the Gitleaks vs TruffleHog comparison walks through every column.

Frequently Asked Questions

What is Gitleaks?
Gitleaks is an open-source secret scanner for git repositories that detects hardcoded credentials, API keys, and other sensitive data. With 25.9k GitHub stars and MIT licensing, it’s one of the most widely adopted secret scanning tools among security professionals and developers.
How does Gitleaks compare to TruffleHog?
Gitleaks focuses on speed and simplicity with a single binary installation and straightforward configuration. TruffleHog offers broader scanning capabilities beyond Git (including Slack, wikis, S3) and verifies if leaked credentials are still active. Gitleaks is faster for Git-only scanning, while TruffleHog provides deeper secret verification.
Can Gitleaks scan Docker images?
Gitleaks scans git repositories, files, directories, and stdin. While it doesn’t directly scan Docker images, you can use it to scan the filesystem of an extracted container or the Dockerfile and source code before building the image.
Is Gitleaks free?
Yes, Gitleaks is completely free and open-source under the MIT license. You can use it in personal projects, commercial products, and CI/CD pipelines without any licensing costs.