Published

Security

Scan Your Git Repo for Leaked API Keys With gitleaks (Free)

Leaked keys in Git history are one of the most common ways accounts get hijacked. Here is how to find them in seconds and what to do if you do.

1. Install gitleaks

On a Mac use Homebrew. It is also available for Linux and Windows from its GitHub page.

brew install gitleaks

2. Scan the full history

Run it in your repo folder. It checks every commit, not just the current files.

gitleaks git -v .

3. Or scan just the files

Useful for a folder that is not a Git repo yet.

gitleaks dir -v .

4. Found a secret? Revoke it first

GitHub says revoking with the provider is the most important step. Create a new key, switch your app to it, then revoke the old one. Removing it from the code does not undo the leak.

5. Stop the next one

On GitHub, open Settings, Code security, and turn on Push protection for yourself. It blocks pushes that contain known secret formats.

Sources

gitleaks on GitHub; GitHub Docs (secret scanning, remediating a leaked secret, push protection).

FAQ

Does GitHub already scan my repos?

GitHub runs secret scanning free on public repositories. Push protection stops secrets before they get there.

Is rewriting Git history enough?

No. Anyone may already have copied the key. Revoke and replace it.