eric spencer  //  formal methods · large language models · systems

back to index

Git Key Guardian

Protect sensitive keys from accidentally being uploaded to your git history at any point.

repo: https://github.com/EricSpencer00/git-key-guardian


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.

Why this project

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.

Features

How it works (short)

  1. Grep-style regex checks using the patterns in patterns/common_patterns.txt (comments and blanks are ignored).
  2. Fixed string checks against your personal keys file ($HOME/.git-key-guardian/personal_keys.txt).

Install

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

Usage

Test locally without installing

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 and Personal Keys

Example patterns included by default:

Implementation notes

Contributing

Contributions are welcome — follow the guidance in CONTRIBUTING.md:

Caveats & best practices

Links


If 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.