Never commit API keys to git — ever
This is the cardinal rule. A key committed to a git repo — even briefly, even to a private repo — should be considered compromised. GitHub's secret scanning will catch known formats immediately and send you an alert. But the key is already in git history, visible to anyone who clones or forks the repo, and indexed by tools that scan for leaked credentials.
What to do instead: use environment variables loaded from a .env file, and make sure .env is in your .gitignore from the moment you create the project. Don't add it later — add it first.
Tip: install git-secrets or run grep -r "sk-" . before any public repo push to catch anything you may have missed.