Home / Vibe Coding / Pushed Your API Key to GitHub? What to Do in the First Hour

Pushed Your API Key to GitHub? What to Do in the First Hour

Pushed your API key to GitHub? Deleting the file doesn't fix it; revoking the key at the provider does

Vibe coding · Security basics · For beginners

Deleting the file doesn’t un-leak it. Killing the key does.

Pushed API key to GitHub? Here is a calm, in-order checklist for the moment you realize your secret is sitting in a public repo — straight from GitHub’s own docs, minus the panic.

You know the feeling. You’re scrolling through your repo on GitHub, admiring the thing you built, and there it is — OPENAI_API_KEY=sk-..., in plain text, in a file anyone on the internet can open. Your stomach drops. Your first instinct is to delete the line, push again, and pretend it never happened.

That instinct is understandable, and it’s also the one move that doesn’t fix anything. Git keeps every version of every file, so your key is still one click away in the commit history. The good news: the real fix is quicker than the cleanup you were about to do.

The short version

Pushed API key to GitHub by accident? Revoke it in the provider’s dashboard first and create a new one. Deleting the file or making the repo private does not remove the key from git history, forks or clones. GitHub’s own docs say to revoke or rotate the secret first, then decide whether rewriting history is even needed.

How I put this together. On Nov 14, 2026 I read GitHub’s official pages on removing sensitive data, secret scanning partners and push protection, GitHub’s changelog posts about OpenAI and Anthropic keys, and Anthropic’s API docs. Every claim below links to one of those.

What I did not do. I didn’t leak a real key to test how fast anyone reacts, and this isn’t a story about my own bill. I couldn’t open OpenAI’s help center when I checked, so where I mention OpenAI, I rely on GitHub’s announcement rather than OpenAI’s own page.

Pushed API key to GitHub: is it still exposed if I delete the file?

Yes. Think of git as a photo album, not a whiteboard. Every commit is a snapshot of your whole project. When you delete the key and commit again, you add a new photo where the key is gone — but the old photo, with the key in it, is still in the album. Anyone can open your repo’s history and look at it.

Making the repo private or deleting it doesn’t reliably help either. GitHub’s documentation on removing sensitive data warns that copies can survive in forks, in other people’s clones, and in cached views on GitHub. You can’t reach into someone else’s copy and delete it.

So the question isn’t “how do I hide the key?” It’s “how do I make the key useless?” A revoked key is just a string of random letters — leak it all you want.

What to do in the first hour, in order

Do these in this order. The first step is the only urgent one; everything after it is cleanup.

Pushed API key to GitHub: first hour steps — revoke, replace, check usage, then stop it happening again
The order matters: kill the key before you touch git. Chart: MindWiredAI. Data source: GitHub Docs, Removing sensitive data from a repository — the “revoke and/or rotate first” guidance.

Step 1: Revoke the key at the provider (do this now)

Log in to the service that issued the key and delete or disable it. Not GitHub — the place where you created the key. For Claude, that’s the API keys page in the Claude Console. For OpenAI, Google, Stripe, Supabase or anyone else, look for “API keys” in that service’s dashboard or settings.

GitHub’s docs say this is the first move: once a secret is revoked or rotated, it “can no longer be used for access” — and rewriting history may not even be necessary after that.

⚡ Why this step can’t wait

An AI API key is tied to your billing. While it works, anyone who finds it can send requests that you pay for. Every other step can wait until tomorrow. This one can’t.

Step 2: Make a new key and put it in the right places

Create a fresh key and paste it into your .env file on your computer — never into a code file. If your app is already live on Vercel, Netlify, Railway or similar, update the key in that host’s environment variable settings too, then redeploy. Forgetting this is one of the classic reasons an app works locally but breaks after deploy.

Step 3: Check your usage and billing

Open the provider’s usage or billing page and look for requests you didn’t make, especially since the time you pushed. If you see something odd, contact that provider’s support and tell them the key was exposed and has been revoked. While you’re there, set a spending limit if the service offers one — Anthropic’s API docs, for example, point to workspaces to separate projects and control spend.

Step 4: Stop it from happening again

Tell git to ignore your secrets file, and stop tracking it if it was already committed. In your project folder’s terminal:

echo ".env" >> .gitignore
git rm --cached .env
git commit -m "Stop tracking .env"
git push

git rm --cached removes the file from git’s tracking but leaves it on your computer, so your app keeps working. If the key was typed straight into a code file instead, move it into .env and read it from there — my .env security guide for vibe coders walks through exactly how.

MoveStops someone using the key?Why
Revoke the key at the provider✓ YesThe key stops working everywhere, including every copy
Delete the line and push again✗ NoThe old commit still shows the key
Make the repo private✗ NoForks and clones made before can keep it
Delete the whole repo✗ NoSame problem, and you lose your project page
Rewrite git history✗ Not by itselfCleans your repo, not copies that already exist

Do I actually need to remove the key from git history?

Usually, for a beginner’s personal project: no, not once the key is revoked. A dead key in your history can’t do anything. GitHub’s docs say the same — after revoking or rotating, rewriting history “may not be necessary.”

If you still want it gone (say, it’s an old secret you can’t rotate, or you just hate seeing it there), GitHub recommends a tool called git-filter-repo, version 2.47 or newer, with a --sensitive-data-removal option, followed by a force-push. But read the warnings on that page before you try it. Rewriting history changes the ID of every commit from the leak onward, can break open pull requests, and can’t be undone once pushed. Anyone with an old clone can push the key right back.

GitHub Support can also clear cached views and pull-request references — but only when the risk “can’t be mitigated by rotating affected credentials.” In other words: even GitHub tells you to rotate first and scrub second.

💡 Caught it before you pushed?

If the key is only in a local commit and hasn’t reached GitHub yet, you’re in a much easier spot: undo that commit, move the key into .env, and commit again. My guide on going back with git when AI breaks your code shows how to undo a commit safely.

What GitHub secret scanning already does for you

You’re not completely alone here. GitHub runs a few safety nets automatically, and it helps to know what they actually do.

Partner alerts. GitHub scans public repositories for secrets from partner companies and sends what it finds straight to that company, which then “decides whether they should revoke the secret.” OpenAI joined in 2021, and GitHub’s announcement says found keys are forwarded to services that “automatically disable them and notify their owners.” Anthropic joined in 2024; GitHub says Anthropic will “revoke the compromised tokens and notify the affected users.”

Push protection. GitHub can block a push that contains a recognized secret before it ever lands. Its docs say push protection for users is on by default for public repositories, and in October 2026 GitHub said it now blocks two more Anthropic key types by default. If GitHub ever refuses your push with a message about a secret, that’s this feature saving you — remove the key from the commit instead of looking for a way around the block.

What happens when a key reaches a public GitHub repo: GitHub scans, alerts the provider, provider may revoke
The safety net, and its gaps. Chart: MindWiredAI. Data source: GitHub Docs, About secret scanning for partners and Push protection for users.

⚠️ The catch

Partner alerts are about public repos, and only for companies in the program. The provider decides whether to revoke, and GitHub doesn’t promise how fast or that you’ll get an email. Push protection only catches key formats GitHub recognizes. Treat these as a seatbelt, not a driver — revoke the key yourself either way.

The honest limitations

This checklist covers API keys you can revoke and replace — the common case for vibe-coded apps. It’s not enough on its own for things you can’t simply rotate, like a leaked customer list or passwords for other people’s accounts; that’s a bigger incident, and you may have legal duties depending on where you and your users are. I also can’t tell you whether a provider will refund charges from a leaked key; I didn’t find a published policy, so ask their support directly. And I didn’t test how quickly any provider actually disables a leaked key — I’m reporting what GitHub says they do, not timing it myself.

Who should actually care

Worth it if: you build with Cursor, Claude Code, Lovable, Bolt or ChatGPT, push your projects to GitHub, and use any paid API key — even “just for testing.”

Maybe not if: your repos are private and only you use them. The risk is lower, not zero — private repos get shared, made public later, or cloned onto other machines.

Skip if: you never put keys in your project at all, or your app has no paid services behind it.

FAQ

Pushed API key to GitHub: what’s the very first thing to do?

Revoke the key in the dashboard of the service that issued it, then create a new one. Don’t start with git. A revoked key is harmless no matter how many copies of it exist.

Is making my repository private enough?

No. GitHub warns that the data can remain in forks, other people’s clones and cached views. Going private stops new visitors; it doesn’t recall copies already made.

GitHub blocked my push because of a secret. What now?

That’s push protection working. The key never reached GitHub. Remove it from your code, put it in .env, undo or amend the commit that contained it, and push again.

Is adding .env to .gitignore enough to protect my keys?

Only for files that aren’t tracked yet. If .env was committed before, you also need git rm --cached .env. And keys pasted directly into code files aren’t covered by .gitignore at all.

The bottom line

Pushed API key to GitHub by accident? You can’t un-publish it — but you can make it worthless in a few minutes. Revoke, replace, check your bill, then ignore your .env. History rewriting is optional homework, not first aid.

Your next step: open the API keys page of every service your project uses and bookmark it, so you’re one click away if this ever happens.

Explore MindWiredAI →

Related free AI guides

Published Nov 14, 2026. Sources checked Nov 14, 2026: GitHub Docs (removing sensitive data, secret scanning for partners, push protection for users), GitHub changelog (June 2021, Aug 2024, Oct 2026), Anthropic API overview.

Tagged:

Leave a Reply

Your email address will not be published. Required fields are marked *

🔥 Don't miss the latest from AI Agent News! Subscribe Now 👉