Redaxa · Privacy, before AI

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.

  1. 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.
  2. 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.
  3. 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.
  4. Remove the key from the current files in a normal commit, so nobody copies it from the latest version.
  5. 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.

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.

Related