هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
Step by step
- Install — a single binary (see the full guide), or run it in a container:
docker run --rm -v "$PWD":/repo zricethezav/gitleaks:v8.28.0 git /repo -v --redact- Scan the whole history (quick answer) and read a finding:
Finding: AWS_SECRET_ACCESS_KEY=REDACTED
RuleID: aws-access-token
File: deploy/old.env
Commit: 3f9c2e1…
Author: alice
Date: 2025-03-11T10:22:41Z- Triage every finding:
| It is… | Do |
|---|---|
| A real secret, still valid | Rotate it now, then remove it from history. |
| A real secret, already revoked | Remove it from history (or document it as revoked). |
| A test value / example | Allow it (step 5). |
- Block new secrets before they are committed — pre-commit framework (for the whole team):
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0
hooks:
- id: gitleakspre-commit installAnd in CI (so nobody can skip the hook):
gitleaks git --log-opts="origin/main..HEAD" -v --redact --exit-code 1- Allow false positives — a config with an allowlist (narrow: paths or exact values), or an inline comment:
[extend]
useDefault = true
[allowlist]
description = "Test fixtures"
paths = ['''tests/fixtures/.*''']api_key = "test-key-not-real" # gitleaks:allow- Already pushed? Rotate first, then clean the history (see the next how-to), and turn on GitHub push protection.
Check that it worked
gitleaks git -v --redact ends with no leaks found, a test commit with a fake key is blocked by the hook, and the CI job fails on a new secret.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Hundreds of findings in an old repo | Years of history, test keys. | Triage by rule and file; rotate real ones; allowlist fixtures. |
| CI finds nothing new | Shallow clone (fetch-depth: 1). | Fetch the history the scan needs (fetch-depth: 0). |
unknown command "detect" | Newer Gitleaks uses git / dir subcommands. | gitleaks git instead of gitleaks detect. |
The hook is skipped (--no-verify) | Local hooks are optional. | Run Gitleaks in CI as a required check. |
| A real secret is in the allowlist | Too wide allowlist (.*). | Allow exact paths/values only; review the config in PRs. |
| Secrets in Docker images or logs | Gitleaks only scans Git/files. | Scan images with Trivy (--scanners secret), keep secrets out of logs. |
Go further
- Command pages: gitleaks, git.
- Next how-tos: Remove a secret from Git history, Find bugs in code with Semgrep, Create a CI pipeline in GitHub Actions.
- Full guide: Gitleaks. At work: Gitleaks. Learn it: Git — Scan for secrets.
1What is the first thing to do when Gitleaks finds a real, valid key?
Rotate (revoke) the key — then clean the history.
2Why run Gitleaks in CI when there is already a pre-commit hook?
Local hooks can be skipped or not installed; CI checks every push.