Practical guide · By Aurelio Avila · November 4, 2026
I committed an API key to GitHub: what to do
A key in a public commit can be found by automated scanners quickly, and a new commit that deletes it does not remove it from history. Here is the order that works: revoke, review, replace, then clean up.
First: the key is exposed, whatever you do next
If the repository is public, assume the key has already been read: automated scrapers look for credential patterns continuously, and the value stays in Git history even after you delete the line. If the repository is private, the key is exposed to everyone with access, to forks, to clones and to any tool that was given a token. Either way the order is the same, and cleaning the history comes last, not first.
- Revoke or rotate the key at the provider. GitHub's guidance on a leaked secret starts here as well. Provider-by-provider steps are on the detector pages, for example GitHub tokens, AWS keys, OpenAI keys and Stripe keys.
- Review usage for the exposure window: from the commit's push time until the revocation. Look for calls, logins, instances or charges you did not make.
- Put the replacement somewhere that Git never sees. An environment variable, your host's secret settings, or a secret manager; and add the file that held the old key (for example
.env) to.gitignore. - Remove the key from the current files in a normal commit, so nobody copies it from the latest version.
- Only then decide about rewriting history. Once the key is revoked, the old value is dead, and rewriting history is hygiene rather than a security fix. It is still worth doing if the history contains other secrets or personal data. GitHub documents the process in Removing sensitive data from a repository, and the tool it points to for the rewrite is git-filter-repo. A rewrite changes commit hashes, so everyone with a clone must re-clone, and forks and cached views are not cleaned by it.
Find out what else is in the repository
One leaked key usually means there are more: a second environment file, an old example config, a token in a test fixture. Before you close the incident, check the whole repository.
- Free web check, public repositories only. Paste the repository link at the Redaxa repository check. It reads the text files of the default branch, shows each finding with the value masked, and lists every file it skipped. Walkthrough: Check a public GitHub repo for leaked API keys. What it reads and what it does not: Free GitHub secret scanner: what the web check reads and its limits.
- Git history. The web check does not read past commits. The Redaxa Windows app can check the history and archives of a public repository locally with a Pro or Business plan. Open-source command-line scanners also read history; pick the one your team already trusts.
- Private repositories. Redaxa checks public repositories only. For private ones, use GitHub's own secret scanning if your plan includes it, or a scanner you run yourself.
A clean result is not proof that nothing is exposed: it means the enabled checks found nothing in the files that were read. Redaxa never tests whether a key works, so a finding means "this looks like a credential", not "this credential is live".
Stop the next one before it is pushed
GitHub's push protection can block a push that contains a supported secret; check in your repository settings whether it is available and switched on for your plan. Keep real values out of example files, and commit a .env.example with placeholders only.
The other common route for the same key is a chat: people paste the failing file into an AI assistant. If that happened too, read I pasted an API key into ChatGPT: what to do now.
Check a public repository free Add the free Chrome extension
FAQ
I committed an API key to GitHub and deleted it in the next commit. Is it safe?
No. The value stays in the repository history, and in any clone or fork made in between. Revoke or rotate the key at the provider; that is what makes the old value useless.
Do I need to rewrite Git history after leaking a key?
Not to be safe: once the key is revoked, the old value is dead. Rewriting history is worth doing if the history also holds other secrets or personal data, and it changes commit hashes for everyone with a clone.
Can Redaxa scan a private repository?
No. Redaxa checks public GitHub repositories only. For private repositories use GitHub's own secret scanning if your plan includes it, or a scanner you run yourself.
Does the free repository check read my Git history?
No. The web check reads the text files of the default-branch snapshot. Git history and archives of public repositories are checked locally in the Windows app with a Pro or Business plan.