Gitleaks Tutorial: 12 Steps, 60 Min [2026] Gitleaks, an MIT-licensed Go tool for detecting hard-coded passwords, API keys and tokens in Git repositories, remains actively maintained as of October 28, 2026, and a tutorial outlines a three-layer defense — a full commit-history scan, a pre-commit hook and a GitHub Actions gate — that can be set up in about 60 minutes. The tutorial notes GitHub processed 7.4 billion commits in September, and that a leaked key stays reachable in history after a follow-up commit deletes the file, so a working-tree scan misses it while a history scan finds it. Gitleaks deprecated its `detect` and `protect` commands in v8.19.0 in favor of `git` and `dir`, and the tool's pattern matching cannot determine whether a found key is still live, unlike TruffleHog's active-credential checks. Gitleaks is an MIT-licensed Go tool that finds hard-coded passwords, API keys and tokens in Git repositories, and as of October 28, 2026 it remains an actively maintained project gitleaks.io https://gitleaks.io/ . You can stack three defenses with it in about an hour: a scan of your full commit history, a pre-commit hook that stops a secret before it enters history, and a GitHub Actions gate that fails any pull request carrying one. Volume is the problem. GitHub processed 7.4 billion commits in September, according to The New Stack https://thenewstack.io/github-7-4b-commits-september/ , and every one of them is a chance for a token to slip through. Worse, a leaked key stays reachable in history after a follow-up commit deletes the file. A scan of the working tree misses it. A scan of history finds it. The pattern also fits agent-driven pipelines. If you already run a headless coding agent through Cursor CLI in GitHub Actions https://shattered.io/cursor-cli-github-actions-headless-agent-2026/ , the same runner hygiene applies: a secret gate on every pull request means an agent mistake cannot ship a credential. The finished project holds a tuned .gitleaks.toml , a pre-commit config, a CI workflow, a baseline strategy for legacy code and a self-test script that proves the whole stack still works after every change. Don't miss new tech stories on Google Add Shattered once in the Google app and our stories show up in your news suggestions. Add now https://www.google.com/preferences/source?hl=en&q=https%3A%2F%2Fshattered.io%2F What Gitleaks Catches and Where It Fits in 2026 Gitleaks matches text against a library of rules. Each rule pairs a regular expression with optional keywords, an entropy floor and allowlists. The keyword acts as a cheap prefilter, so the engine only runs the expensive regex on lines that contain a hint such as ghp or AKIA . The entropy floor then discards low-randomness strings like changeme123 , which look like secrets but are not. That combination keeps the tool fast on large histories and keeps noise tolerable. The open-source project covers the common cloud, SaaS and source-host token formats out of the box. You can extend the default rule set with your own patterns, which matters because the secrets most likely to hurt you are internal ones that no public rule library knows about. An internal service token, a legacy signing key or a vendor credential with a custom prefix all need a custom rule. Three scan modes Gitleaks offers three entry points. gitleaks git walks commit history or only staged changes when you add --staged . gitleaks dir scans files on disk and ignores Git entirely, which suits build artifacts and unpacked archives. gitleaks stdin reads piped text. Older tutorials use detect and protect . The project deprecated both in v8.19.0, and while they still run, new work should use git and dir . Gitleaks, TruffleHog and GitHub native scanning Gitleaks is not the only option, and it does not replace GitHub features. The table below compares the approaches by design, not by benchmark, because rule coverage shifts with every release and no public head-to-head number is stable enough to quote. | Approach | Where it runs | Main strength | Main limit | |---|---|---|---| | Gitleaks | Laptop, CI runner, any Git host | Fast, single binary, TOML rules you own, works offline | Pattern matching only, so it cannot tell you whether a key is still live | | TruffleHog | Laptop, CI runner, many data sources | Commonly used when checking whether a found credential is still active matters | Heavier setup, more network calls, different rule format | | GitHub secret scanning | Inside GitHub only | Hosted, no pipeline to maintain, GitHub keeps shipping fixes to it October 2026 updates included | Tied to GitHub, and advanced security features sit behind a paid license | | Pre-commit hook plus Gitleaks | Developer machine | Stops a secret before it exists in history | Developers can skip it with --no-verify | The practical answer is to layer them. Run Gitleaks locally and in CI because it works on every host and you control the rules. Keep GitHub native scanning on as a second net if your plan includes it. Consider a verification-focused tool when you need to triage hundreds of historical findings and want to know which ones still open a door. Prerequisites and Versions Everything below runs on Linux or macOS. Windows users should work inside WSL, because the hook scripts are Bash. Keep the versions in the table in mind when you copy commands, since flag names and config syntax have moved across Gitleaks releases. | Tool | Version | Why you need it | |---|---|---| | Git | A recent release recommended | Hooks, --staged scans and history walking. Git 2.54 adds config-based hooks, which pre-commit 4.6.0 and later handle better | | Gitleaks | Latest stable release issue reports in October 2026 reference v8.30.1 | The scanner. Config syntax below needs v8.25.0 or newer | | pre-commit | v4.7.0 newest release | Manages the hook. It fixed language: node hooks for git commit -a and submodules after a v4.6.1 regression | | Python | A currently supported Python 3 release | Runs pre-commit and the report summarizer | | Bash and OpenSSL | Any current version | The self-test script generates random fake tokens | | GitHub repository | Actions enabled | Hosts the CI gate. The pull request gate works on GitHub Free, Pro and Team plans | | jq optional | 1.6 or newer | Quick JSON inspection of reports | | Docker optional | Any current release | Alternative way to run Gitleaks without installing it | pre-commit itself costs nothing, and so does Gitleaks. Budget about 60 minutes the first time. The longest single wait is the first pre-commit run, because the hook compiles Gitleaks from source and pre-commit bootstraps a Go toolchain if it cannot find one. One more prerequisite is mental. Treat every token you plant in this exercise as radioactive. Generate fakes at runtime, never paste a real credential into a test, and never push the demo repository to a public remote. Secret scanners on the receiving end, including GitHub push protection, will flag test tokens that look real. Steps 1 to 3: Install Gitleaks and Run the First History Scan Step 1: Install Gitleaks Pick one install path. Homebrew is the fastest on macOS and Linux. Docker avoids a local install. Building from source suits locked-down machines, and the project build has moved to a recent Go toolchain Go 1.24 at last check , so use a current Go release. For release binaries, take the newest tag from the project releases page rather than a version quoted in an old blog post. Option A: Homebrew brew install gitleaks Option B: Docker no local install docker pull zricethezav/gitleaks:latest Option C: build from source git clone https://github.com/gitleaks/gitleaks.git cd gitleaks make build sudo install -m 0755 gitleaks /usr/local/bin/gitleaks Verify gitleaks version Watch out for look-alike forks. Search results in October 2026 surface a third-party fork that publishes pre-release tags mimicking the upstream numbering, such as 8.30.1-v.63 , which its release page marks as a pre-release. Those are not upstream releases. Install from the official gitleaks/gitleaks repository only. Step 2: Create a demo repository with a planted leak The demo repo needs a secret that sits in history but not in the current files. That shape is the most common real-world failure: a developer commits a token, notices, deletes it in the next commit, and believes the problem is gone. The script below generates a fake GitHub-style token at runtime so no static string ever lands in your shell history or in this repo. mkdir secret-guard-demo && cd secret-guard-demo git init -b main git config user.name "Demo User" git config user.email " email protected " mkdir -p config src tests/fixtures reports scripts FAKE TOKEN="ghp $ openssl rand -hex 18 " cat config/settings.py <