Safeguard
Application Security•

Best secrets scanning tools for Git repos and pre-commit

Gitleaks, TruffleHog, detect-secrets, ggshield, git-secrets and GitHub secret scanning compared on sources, verification, license and where they run.

Safeguard Security Team
5 min read

The best secrets scanning tool is one that runs before a commit lands and again over your full history. Gitleaks and detect-secrets are light and free. TruffleHog verifies whether a found secret is live. ggshield and GitHub secret scanning are hosted services. Use a pre-commit hook plus a CI scan.

Safeguard publishes this guide and sells a competing product, so we describe other tools only from their own documentation, as of 19 October 2026.

Key takeaways

  • Catching a secret at commit time is cheap. Removing it from history and rotating it is not.
  • Verification (checking whether a key still works) helps you decide what to rotate first.
  • A baseline file lets you adopt a scanner on a messy repo without fixing everything on day one.
  • Any secret that reached a remote must be treated as leaked and rotated, even if you delete it.

How do secrets scanners find secrets?

They use patterns for known token formats, entropy checks for random looking strings, and keyword checks for variable names such as password. detect-secrets documents all three as plugin types. Some tools then call the issuing service to see if the secret still works.

Click through it at your own pace, or open it full screen.

How do the main tools compare?

ToolType and licenseWhere it scans (per docs)Distinctive feature
GitleaksOpen source, MITGit history, directories, stdinBaseline file; TOML rules; pre-commit and GitHub Action
TruffleHogOpen source, AGPL-3.0Git, cloud storage, Docker images, CI systems, Postman and moreMarks results verified, unverified or unknown
detect-secretsOpen source, Apache-2.0Code base, run as pre-commitBaseline approach; about 27 plugins
git-secretsOpen source, Apache-2.0Commits, commit messages, merges via hooksAWS patterns built in
ggshieldCLI for GitGuardianLocal files, CI, Docker images, pre-commit and pre-receive hooksNeeds a GitGuardian API key; detects 600+ secret types
GitHub secret scanningGitHub featureAll branches of repository history, issues, pull requests, wikisFree on public repositories; private repos need GitHub Secret Protection

What are the limits of each tool?

Gitleaks says it is "feature complete" and that new releases will be security patches only, with the maintainer shifting focus to a project called Betterleaks. It is still a solid choice, but plan for that.

TruffleHog is AGPL-3.0 licensed and contributions require a CLA. Check that the license fits your use. Its README gives two different detector counts (over 800 secret types classified, over 700 detectors with verification), so do not quote one number without checking.

detect-secrets is built to stop new secrets entering a codebase rather than clean up old ones.

git-secrets warns that its AWS patterns "are not guaranteed to catch them all." Hooks must also be installed in every repo, so a package install alone protects nothing.

ggshield sends data to GitGuardian. Its docs say only metadata such as call time, request size and scan mode is stored, not your files or secrets.

GitHub secret scanning validates secrets with partners and can run validity checks, which may contact the issuing service.

How do I choose a secrets scanning tool?

  1. Does it run as a pre-commit hook and in CI?
  2. Can it scan full history, not just the latest commit?
  3. Does it support a baseline so old findings do not block new work?
  4. Can it verify a secret is live?
  5. Does any data leave your network, and are you comfortable with that?
  6. Can you add custom rules for your internal token formats?
  7. Does the license fit your company policy?

What should I do when a secret is found?

Rotate it first, then clean up. Revoke the credential at the provider, issue a new one, check logs for use of the old one, and only then consider rewriting history. Deleting the line does not make a pushed secret safe.

Safeguard is not a replacement for a dedicated secrets scanner in this comparison. It adds dependency and malicious package checks in the Gold registry at gold.safeguard.sh, and a free in-browser dependency scan at gold.safeguard.sh/scan that never sends your file to a server.

Frequently asked questions

Is there a free secrets scanner?

Yes. Gitleaks (MIT), detect-secrets (Apache-2.0) and git-secrets (Apache-2.0) are free. TruffleHog's open source edition is AGPL-3.0.

Does GitHub scan private repositories for free?

Per GitHub's docs, public repositories are scanned for free. Organization private and internal repositories need GitHub Secret Protection.

What is a baseline file?

It records secrets that already exist so future scans report only new ones. Gitleaks and detect-secrets both support it.

Do I need to rotate a secret I removed from the repo?

Yes, if it was ever pushed. Anyone who cloned or forked the repo may still have it.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.