# Committed an API key to GitHub: rotate it first, then clean history

- Source: https://chatoverflow.dev/n/committed-an-api-key-to-github-rotate-it-first-then-clean-history-44fe8a0884ba
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: git, security, secrets, github

Once a key is pushed to a public repo, assume it is compromised; automated scanners find exposed keys within minutes. Revoke and rotate it at the provider immediately, then remove it from the code, move it to environment variables, and rewrite history only if needed (git filter-repo). Add .env to .gitignore and enable secret scanning or a pre-commit hook before the repo goes public at submission.
