# AI use cases for Gitleaks (gitleaks/gitleaks)

Repo: [gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) | Use cases: 3 | Page: https://dedupedai.com/use-cases/gitleaks-gitleaks/

Gitleaks detects hardcoded secrets such as passwords, API keys and tokens in git history, directories and files, or anything piped to stdin. It runs as a CLI, a Docker image, a pre-commit hook or a GitHub Action, supports baselines so only new findings are reported, custom TOML rules, redaction and JSON, CSV, JUnit and SARIF reports. The maintainer has declared it feature complete, with future releases limited to security patches.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Scan a repo's full history for leaked secrets: https://dedupedai.com/use-cases/gitleaks-gitleaks/scan-a-repo-history-for-leaked-secrets/
- Stop secrets before they are committed: https://dedupedai.com/use-cases/gitleaks-gitleaks/block-secrets-with-a-pre-commit-hook/
- Adopt secret scanning on an old repo without the noise: https://dedupedai.com/use-cases/gitleaks-gitleaks/adopt-gitleaks-on-a-noisy-repo-with-a-baseline/

## How to scan a repo's full history for leaked secrets with Gitleaks

Repo: [gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Run Gitleaks over every commit to find passwords, API keys and tokens that were ever committed.

**Who it is for:** A team lead inheriting an old repo who needs to know whether credentials ever leaked into it.

**The problem:** A secret deleted in a later commit is still in git history, where anyone with the repo can find it.

**The outcome:** A report of every secret found, with the file, line, commit and author, so you can rotate them.

### Steps

1. Install with `brew install gitleaks` or `docker pull zricethezav/gitleaks:latest`
2. Run `gitleaks git -v` inside the repo to scan its git history with verbose output
3. Save a report with `gitleaks git --report-path gitleaks-report.json`
4. Use --redact so secrets are hidden from logs and stdout when you share output
5. Rotate every real credential it finds; removing it from the code alone is not enough

### Prompt to paste into your agent

```text
Install gitleaks/gitleaks and scan the full git history of <repo> with redaction on, saving a JSON report. Summarize the findings by rule and file, mark likely false positives, and list which credentials I should rotate first.
```

### Caveat

Gitleaks is feature complete and now gets security patches only; the maintainer points to Betterleaks for new development.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/gitleaks-gitleaks/scan-a-repo-history-for-leaked-secrets/

## How to stop secrets before they are committed with Gitleaks

Repo: [gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Add Gitleaks as a pre-commit hook so a commit containing a secret fails on the developer's machine.

**Who it is for:** A small team that keeps finding API keys in pull requests after the fact.

**The problem:** Catching secrets in review is too late: once pushed they are in history and must be rotated.

**The outcome:** Commits that contain hardcoded secrets fail locally with a Detect hardcoded secrets message.

### Steps

1. Install pre-commit from the pre-commit website
2. Create .pre-commit-config.yaml at the repo root with the Gitleaks repo, a rev and the Gitleaks hook id
3. Update to the latest version with `pre-commit autoupdate`
4. Install the hook with `pre-commit install`
5. Try a commit with a fake secret to confirm it fails; SKIP=Gitleaks bypasses the hook when you truly need to

### Prompt to paste into your agent

```text
Set up gitleaks/gitleaks as a pre-commit hook in <repo>: write .pre-commit-config.yaml, run pre-commit autoupdate and pre-commit install, then prove it works by trying to commit a file with a fake API key. Do not commit the test file.
```

### Caveat

Anyone can skip a local hook, so pair it with the GitHub Action or a CI scan for real enforcement.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/gitleaks-gitleaks/block-secrets-with-a-pre-commit-hook/

## How to adopt secret scanning on an old repo without the noise with Gitleaks

Repo: [gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) | Difficulty: Intermediate | Time: 45 minutes | Basis: From the README

Save current findings as a baseline so later scans only report new secrets.

**Who it is for:** A security engineer rolling out scanning on a large repo with years of known findings.

**The problem:** Hundreds of old findings make a new scanner useless because nobody can see the new ones.

**The outcome:** Scan reports that contain only issues introduced after the baseline.

### Steps

1. Create a baseline report with `gitleaks git --report-path gitleaks-report.json`
2. Triage the baseline once and rotate anything real
3. Run later scans with `gitleaks git --baseline-path gitleaks-report.json --report-path findings.json`
4. Tune rules in a custom .gitleaks.toml that extends the default config with useDefault
5. Choose a report format such as sarif or junit with --report-format to feed your CI

### Prompt to paste into your agent

```text
For <repo>, create a gitleaks/gitleaks baseline report, then add a CI step that runs gitleaks with --baseline-path so only new findings fail the build, writing SARIF output. Add a .gitleaks.toml that extends the default config.
```

### Caveat

A baseline hides old findings; it does not make them safe, so rotate real secrets before you baseline them.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/gitleaks-gitleaks/adopt-gitleaks-on-a-noisy-repo-with-a-baseline/
