Skip to main content
Vibe Code Forum

Question: I pushed my API key to GitHub by mistake. What now?

It happens to experienced developers too. An API key, database password or secret ended up in a commit and was pushed to GitHub (or pasted somewhere public). What are the right steps, in order?

Solution

By Vibe Code Forum team in post #2

Act now, in this order. Speed matters: bots scan public repositories for keys within minutes.

  1. Revoke (or "roll") the key at the provider straight away. Go to the service's dashboard (the AI provider, Stripe, Supabase and so on), delete or rotate the leaked key and create a new one. This is the only step that actually makes you safe. Deleting the file or the commit does not, because the key may already be copied and stays in Git history.
  2. Check for damage. Look at the provider's usage and billing for activity you don't recognise. If there is any, contact their support; many have a process for leaked keys.
  3. Put the new key in the right place: an environment variable, in a .env file that is listed in .gitignore, and in your host's settings. See Environment variables and .env files.
  4. Remove the old key from the code and commit. Optionally clean it from history too (your AI tool can help with tools made for this), but only after step 1; history cleaning is tidy-up, not protection.
  5. Prevent it next time. Keep .env in .gitignore from the very first commit, keep repositories private unless they need to be public, and turn on GitHub's secret scanning and push protection for your repositories, which can block a push that contains a known key format.

If a database password leaked, also check who connected and change the password. If customer data might have been exposed, you may have legal duties to tell people; get advice.

Read it in context

Act now, in this order. Speed matters: bots scan public repositories for keys within minutes.

  1. Revoke (or "roll") the key at the provider straight away. Go to the service's dashboard (the AI provider, Stripe, Supabase and so on), delete or rotate the leaked key and create a new one. This is the only step that actually makes you safe. Deleting the file or the commit does not, because the key may already be copied and stays in Git history.
  2. Check for damage. Look at the provider's usage and billing for activity you don't recognise. If there is any, contact their support; many have a process for leaked keys.
  3. Put the new key in the right place: an environment variable, in a .env file that is listed in .gitignore, and in your host's settings. See Environment variables and .env files.
  4. Remove the old key from the code and commit. Optionally clean it from history too (your AI tool can help with tools made for this), but only after step 1; history cleaning is tidy-up, not protection.
  5. Prevent it next time. Keep .env in .gitignore from the very first commit, keep repositories private unless they need to be public, and turn on GitHub's secret scanning and push protection for your repositories, which can block a push that contains a known key format.

If a database password leaked, also check who connected and change the password. If customer data might have been exposed, you may have legal duties to tell people; get advice.

Nobody has confirmed this yet. If you try it, say how it went.

More in Ask for help