Skip to content
git-secrets

git-secrets

Category: Secrets
License: Free (Open-Source, Apache-2.0)
Suphi Cankurt
Suphi Cankurt
+8 Years in AppSec
Updated June 11, 2026
4 min read
Key Takeaways
  • git-secrets installs three git hooks — pre-commit, commit-msg, and prepare-commit-msg — that block commits containing prohibited patterns.
  • Ships AWS credential patterns via git secrets –register-aws and supports custom patterns and providers for any secret format.
  • Pure regex-and-git-hook design with no machine learning, entropy analysis, or live credential verification.
  • Open-source under Apache-2.0 with roughly 13,300 GitHub stars, developed and maintained by AWS Labs.

git-secrets is AWS Labs’ open-source tool that prevents you from committing secrets and credentials into git repositories. It works by installing git hooks that scan your changes against prohibited patterns before each commit goes through.

The tool ships with AWS credential patterns out of the box and lets you register your own patterns for any secret format. It is intentionally small: pure regex matching wired into git hooks, with no machine learning, entropy analysis, or hosted dashboard.

I reach for git-secrets on AWS-heavy repositories where blocking access keys at commit time covers the highest-risk leak. It does less than newer scanners, but the narrow scope is also why it is trivial to install and reason about.

awslabs/git-secrets GitHub repository page showing the Apache-2.0 licensed git-hook scanner, its source files, and project README

What is git-secrets?

git-secrets is a command-line tool from AWS Labs that blocks secrets from entering version control. According to the project, it “prevents you from committing passwords and other sensitive information to a git repository.”

It is licensed under Apache-2.0, has roughly 13,300 GitHub stars, and remains actively maintained. The tool runs entirely locally — there is no account, no API, and no network call to a vendor service.

The detection model is deliberately narrow. git-secrets matches egrep-compatible regular expressions against your changes, then filters the matches through an allowlist. If anything survives that filter, the commit fails.

How does git-secrets work?

Flow diagram showing git commit triggering the git-secrets pre-commit hook, which scans the staged diff against AWS and custom regex patterns, then blocks the commit on a match or lets it proceed when clean

You wire git-secrets into a repository with git secrets --install, which adds three hooks. The pre-commit hook checks files changed in the commit, commit-msg checks the commit message text, and prepare-commit-msg checks that a merge will not introduce a prohibited pattern anywhere in its history.

git secrets --scan terminal output flagging a hardcoded AWS access key in config.py with an [ERROR] Matched one or more prohibited patterns message and mitigation suggestions

On each commit, the relevant hook scans the staged changeset against the registered prohibited patterns. A match that is not covered by an allowlist pattern causes the hook to exit non-zero, which aborts the commit and prints the filename, line number, and matching line.

AWS detection is opt-in through git secrets --register-aws. That command registers patterns for AWS access key IDs, secret access key assignments, and account IDs, and it also pulls in credentials from your local ~/.aws/credentials file.

AWS Labs is explicit about the limits of this approach. The documentation notes that the registered patterns “should catch most instances of AWS credentials” but are “not guaranteed to catch them all.”

Beyond commit-time hooks, you can scan on demand. git secrets --scan checks files directly, with --cached, --untracked, and --no-index flags to widen what gets inspected, and git secrets --scan-history walks every revision in the repository.

Key features

git-secrets keeps a small, focused surface. The table below summarizes its main commands and mechanisms.

FeatureDetails
Hook installationgit secrets --install adds pre-commit, commit-msg, prepare-commit-msg
AWS patternsgit secrets --register-aws for access keys, secret keys, account IDs
Custom patternsgit secrets --add 'pattern' registers prohibited regexes
Custom providersgit secrets --add-provider groups reusable pattern sets
On-demand scangit secrets --scan with --cached, --untracked, --no-index
History scangit secrets --scan-history walks all revisions
Allowlisting--allowed patterns or a .gitallowed file in the repo root
LicenseApache-2.0

Prohibited patterns and providers

You register a prohibited pattern with git secrets --add 'pattern', where the pattern is an egrep-compatible regular expression. This lets you describe internal token formats, private key headers, or any other string shape you never want committed.

For reusable pattern sets, git secrets --add-provider registers a custom provider — a command that outputs a list of patterns. Providers make it practical to share a standard rule set across many repositories without copying patterns by hand.

Allowlisting false positives

git-secrets filters scan results through allowed patterns before deciding whether to fail. You add an exception with git secrets --add --allowed 'pattern', or list exceptions in a .gitallowed file committed to the repository root.

The .gitallowed file supports comments with #, and allowlist patterns can include filename and line-number context. This is how teams suppress recurring false positives such as documented example keys like AKIAIOSFODNN7EXAMPLE.

When to use git-secrets

git-secrets fits teams that work heavily in the AWS ecosystem and want a lightweight, local guard against committing access keys. Its narrow scope and zero runtime dependencies make it easy to roll out across many repositories.

The trade-off is breadth. git-secrets is pattern-only: it has no entropy analysis to catch random-looking high-entropy strings, and no live verification to confirm whether a found credential is still active.

For wider provider coverage or git-history-first auditing, Gitleaks offers regex plus entropy detection with SARIF output. TruffleHog adds active credential verification across hundreds of detectors, and detect-secrets brings a baseline workflow for brownfield codebases with existing secrets.

git-secrets is the right pick when AWS credentials are your primary concern and you value a tool you can read, audit, and install in minutes over a broader feature set.

Tip
Best for
AWS-centric teams that want a simple, local git-hook guard against committing AWS access keys and custom-pattern secrets, without entropy analysis, verification, or a hosted service.

Frequently Asked Questions

What is git-secrets?
git-secrets is an open-source tool from AWS Labs that prevents you from committing secrets and credentials into git repositories. It installs git hooks that scan your changes against prohibited patterns and blocks any commit that would introduce a match, with built-in patterns for AWS credentials.
How does git-secrets detect AWS credentials?
Running git secrets –register-aws registers patterns for AWS access key IDs, secret access keys, and account IDs, plus credentials found in your local ~/.aws/credentials file. AWS Labs notes these patterns catch most AWS credentials but are not guaranteed to catch every instance.
Can git-secrets detect secrets other than AWS keys?
Yes. You register any prohibited pattern with git secrets –add ‘pattern’ and group reusable pattern sets into custom providers with git secrets –add-provider. Because matching uses egrep-compatible regular expressions, you can describe any secret format your organization uses.
How is git-secrets different from Gitleaks or TruffleHog?
git-secrets is a deliberately simple regex-and-git-hook tool focused on AWS credentials and custom patterns. It has no entropy analysis, no live credential verification, and no git-history-first scanning workflow. Gitleaks and TruffleHog cover broader provider sets and offer features like entropy detection or active verification.