_____ _ ____
| ____|_ __(_) ___ / ___| _ __ ___ _ __ ___ ___ _ __
| _| | '__| |/ __| \___ \| '_ \ / _ \ '_ \ / __/ _ \ '__|
| |___| | | | (__ ___) | |_) | __/ | | | (_| __/ |
|_____|_| |_|\___| |____/| .__/ \___|_| |_|\___\___|_|
|_|
Git Key Guardian is a lightweight pre-commit hook and helper toolkit that scans staged changes for common secret patterns and your own personal keys, helping you catch accidental commits of API keys, tokens, and credentials before they land in your git history.
Developers frequently commit secrets by accident — API keys, SSH keys, cloud credentials, and other sensitive strings can slip into commits or CI logs. Git Key Guardian provides a small, opt-in guardrail that runs locally (as a shared hook) and reports matches to a configurable set of regex patterns and a personal key list.
The tool is deliberately simple and conservative: it scans only staged changes, uses maintainable regex patterns, and supports exact-string matches for keys you care about tracking.
patterns/common_patterns.txt (one per line, inline comments allowed).$HOME/.git-key-guardian/personal_keys.txt.core.hooksPath so it can protect all your local repos.git commit, the pre-commit hook captures the staged diff with zero context and extracts newly added lines (those starting with a single +).patterns/common_patterns.txt (comments and blanks are ignored).$HOME/.git-key-guardian/personal_keys.txt).Clone the repo and run the installer script. The installer copies the pre-commit hook to a shared hooks directory and configures git to use it globally.
git clone https://github.com/EricSpencer00/git-key-guardian.git
cd git-key-guardian
chmod +x ./scripts/install.sh
./scripts/install.sh
The installer will copy patterns to $HOME/.git-key-guardian/patterns/commonpatterns.txt and install the hook under $HOME/.git-key-guardian/hooks/pre-commit. It also creates an editable personalkeys.txt file for your own keys.
To uninstall, remove the shared hooks directory or run:
git config --global --unset core.hooksPath
git add.git commit — the hook will automatically scan staged changes.If you want to test the hook behavior without changing your global git configuration, create a temporary repo and run a commit as described in CONTRIBUTING.md:
mkdir /tmp/gkg-test && cd /tmp/gkg-test && git init -q
cat > test.txt <<'EOS'
ess kay _ live_1234567890abcdefghijklmn
not_a_key AKIAABCDEFGHIJKLMNOP
random text
EOS
git add test.txt
GIT_DIR=.git GIT_WORK_TREE=. git commit -m "test" || true
You should see the hook report any matches and prompt to proceed.
patterns/common_patterns.txt. Rules:/.../ delimiters.# are allowed.Example patterns included by default:
sklive[0-9a-zA-Z]{24} (Stripe live keys)sk-[A-Za-z0-9]{48} (Older OpenAI key format)AKIA[0-9A-Z]{16} (AWS Access Key ID)ssh-rsa\s+[A-Za-z0-9+/=]+ (SSH public keys)$HOME/.git-key-guardian/personal_keys.txt. Lines beginning with # are ignored.grep -En -f to search staged additions.grep -Fn -f after removing comment/blank lines.git diff --cached --unified=0 + awk filter for ^+[^+]).Contributions are welcome — follow the guidance in CONTRIBUTING.md:
examples/ when adding or changing patterns.scripts/install.shhooks/pre-commitpatterns/common_patterns.txtCONTRIBUTING.mdIf you want any part shortened for a project page summary, or expanded with screenshots and example outputs from the hook, I can add them next.