Gitleaks: Open-Source Secret Scanner for Git Repos
What Gitleaks is
Gitleaks is a command-line tool for detecting secrets such as passwords, API keys and tokens in git repositories, plain files and directories, and anything piped to it through standard input. It is written in Go, released under the MIT licence, and has been around since January 2018, which makes it one of the longer-lived open-source secret scanners. The repository describes itself in four words: "Find secrets with Gitleaks".
The problem it targets is familiar to anyone who has reviewed a pull request late at night: a credential gets hard-coded "just for testing", committed, and then lives forever in git history even after the line is deleted. Gitleaks scans both the current state of a tree and the full commit history, so it catches secrets that were removed from the working copy but are still recoverable from old commits. It is aimed at individual developers who want a pre-commit safety net, platform and security teams who want a CI gate, and anyone auditing an existing repository before open-sourcing it.
One important status note up front: the README now opens with a warning that Gitleaks is feature complete. The maintainer states that new features are no longer being merged and that future releases will be security patches only, with development focus moving to a separate project called Betterleaks. That does not make Gitleaks unusable, but it changes how you should think about adopting it (see the section on things to know below).
How it works
At its core Gitleaks is a rule engine. Each rule combines a Go regular expression with optional extras: a capture group that holds the actual secret, a minimum Shannon entropy for that group, a path regex, keywords for cheap pre-filtering, tags for reporting and allowlists for suppressing false positives. The project links to a blog post titled "Regex is (almost) all you need" for readers who want the reasoning behind the detection engine. A large default rule set ships inside the binary; you can replace it entirely or extend it with your own rules.
There are three scanning modes:
- git scans local git repositories. Under the hood it runs
git log -pand scans the patches, and you can pass options to that command with--log-opts, for example to restrict a scan to a commit range. Without a path argument it scans the current directory as a repo. - dir (aliases
filesanddirectory) scans directories and individual files on disk, regardless of git. - stdin scans whatever is streamed into it, which makes it easy to plug into other pipelines.
Each finding reports the matched line, the extracted secret, the rule ID, its entropy, the file and line, and, for git scans, the commit, author, email and date. Every finding also carries a fingerprint built from the commit, path, rule and line, which is what you use to ignore specific known findings later. Note that the older detect and protect commands were deprecated in v8.19.0 in favour of git, dir and stdin; they still work but are hidden from --help.
Key features
- Configurable rules in TOML. A configuration file can define rules from scratch or set
[extend] useDefault = trueto inherit the built-in rules and override or disable individual ones (for exampledisabledRules = [ "generic-api-key"]). - Config discovery order. Gitleaks looks for config in a fixed order: the
--configflag, theGITLEAKS_CONFIGenvironment variable (a path),GITLEAKS_CONFIG_TOML(the file content itself), and finally a.gitleaks.tomlin the target path. - Allowlists at two levels. Rule-level and global allowlists can match on commits, paths, regexes or stopwords, combined with
ORorANDconditions. Since v8.25.0 an allowlist can target a list of rules viatargetRules. - Composite rules. Added in v8.28.0 and marked experimental, these let a primary rule report only when one or more
requiredauxiliary rules also match, optionally within a given number of lines or columns. - Inline and file-based ignores. A
gitleaks:allowcomment on a line skips that secret; a.gitleaksignorefile at the repo root lists fingerprints to ignore. - Baselines. Any previous report can act as a baseline so that later scans only surface new findings, which is useful for large repos with long histories.
- Decoding. With
--max-decode-depth, Gitleaks recursively decodes percent, hex and base64-encoded text before matching. It is off by default. - Archive scanning. With
--max-archive-depth, it extracts and scans zip files, tarballs and nested archives, reporting inner paths separated by!. Also off by default. - Report formats. JSON, CSV, JUnit and SARIF are built in, and a custom Go
text/templatecan produce any other format. - Redaction and exit codes.
--redactmasks secrets in logs (fully or by percentage), and the exit code on findings is configurable with--exit-code(default 1).
Getting started
The README lists Homebrew, Docker and building from source, and prebuilt binaries for many platforms are available on the releases page.
# MacOS
brew install gitleaks
# Docker (DockerHub)
docker pull zricethezav/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] [OPTIONS] [SOURCE_PATH]
# From Source (make sure `go` is installed)
git clone https://github.com/gitleaks/gitleaks.git
cd gitleaks
make build
Scanning a directory and streaming a file through stdin look like this, per the README:
gitleaks dir -v path_to_directory_or_file
cat some_file | gitleaks -v stdin
To create a baseline report and then report only new findings on later runs:
gitleaks git --report-path gitleaks-report.json # This will save the report in a file called gitleaks-report.json
gitleaks git --baseline-path gitleaks-report.json --report-path findings.json
For a pre-commit hook, the README shows a .pre-commit-config.yaml entry pointing at https://github.com/gitleaks/gitleaks with hook id gitleaks, followed by pre-commit autoupdate and pre-commit install. A blocked commit prints "Detect hardcoded secrets...Failed", and prefixing a commit with SKIP=gitleaks bypasses the hook when needed. There is also a separate Gitleaks-Action for GitHub Actions.
Use cases
- Pre-commit protection. Stop a developer from committing a token before it ever reaches a shared remote, which is far cheaper than rotating a leaked key.
- CI gating. Run a scan in the pipeline and fail the build on findings, emitting SARIF or JUnit so results show up in existing code-scanning or test dashboards.
- History audits. Before open-sourcing an internal repo, run a full
gitscan across all commits to find credentials buried in old history. - Legacy repos with known noise. Generate a baseline once, then enforce "no new secrets" without first cleaning up every historical finding.
- Artifact and log checks. Use
dirwith archive scanning on build outputs, or pipe logs and command output throughstdin. - Organisation-specific tokens. Extend the default config with rules for internal token formats, or extend a built-in rule such as
gitlab-patwhen a self-hosted GitLab uses a custom prefix.
How it compares
The only alternative the README itself points to is Betterleaks, which the Gitleaks maintainer is now focusing on. Beyond that, Gitleaks sits in the same space as other secret scanners such as TruffleHog and detect-secrets, and as the built-in secret scanning offered by some git hosting platforms. Gitleaks' distinguishing traits, based on its own documentation, are a single Go binary with no service to run, a TOML rule format that can extend the defaults, and fingerprint-based ignores and baselines. Whether another tool's verification of live credentials or hosted dashboards matter more depends on your setup; evaluate them against your own repositories rather than relying on feature lists.
Things to know before adopting
- Maintenance mode. The README states that Gitleaks is feature complete and that future releases will be security patches only. Existing behaviour should stay stable, which suits a CI gate, but do not expect new rule types or integrations. Keep an eye on Betterleaks if you need active feature development.
- Regex-based detection. Like any pattern-based scanner it produces false positives and can miss secrets in unusual formats. Plan to tune allowlists, entropy thresholds and disabled rules for your codebase.
- Git scans only see additions. The README notes that Gitleaks looks at additions in git history, which is relevant when designing composite rules.
- Experimental pieces. Composite rules and the
.gitleaksignorefeature are both described as experimental and subject to change. - Command changes. If you have old scripts using
detectorprotect, they still run, but migrate them togitanddir. - Licence. MIT, so there are no copyleft obligations when embedding it in internal tooling or CI images.
Project activity
As of October 2026 the repository has about 30,155 stars and more than 2,400 forks. It was created in January 2018, is written in Go and is licensed under MIT. Its most recent push was at the end of September 2026, consistent with the security-patch-only status described in the README. Docker images are published on Docker Hub (zricethezav/gitleaks) and GitHub Container Registry.
Source code: github.com/gitleaks/gitleaks. Project site: gitleaks.io.
Enjoying this project?
Discover more amazing open-source projects on TechLogHub. We curate the best developer tools and projects.
Repository:https://github.com/gitleaks/gitleaks
GitHub - gitleaks/gitleaks: Gitleaks: Open-Source Secret Scanner for Git Repos
Gitleaks is an MIT-licensed Go tool that finds hard-coded secrets such as API keys, passwords and tokens in git history, directories and stdin, with TOML rules,...
github - gitleaks/gitleaks
Related Projects
Caddy: Web Server With Automatic HTTPS
Go web server and reverse proxy with automatic HTTPS, a simple Caddyfile and a live JSON config API.
Gitea: Self-Hosted Git Service with CI/CD and Packages
Lightweight self-hosted Git forge with pull requests, issues, packages and Actions CI/CD.
LocalAI: Self-Hosted OpenAI-Compatible AI Engine
Self-hosted engine that runs LLM, voice, image and video models behind OpenAI-compatible APIs.
Maintain Gitleaks: Open-Source Secret Scanner for Git Repos? Add the badge to your README
Show that the project is featured on TechLogHub and send readers to this write-up.
[](https://techloghub.com/open-source/gitleaks?utm_source=techloghub_badge&utm_medium=referral&utm_campaign=readme)
