The env file your .gitignore does not protect is the one that leaks
Ignore rules cover .env and .env.local. They deliberately do not cover .env.example — the one env file a repo is meant to commit, and therefore the one a live key can ride out on.
How do I check whether an API key was ever committed to git?
Run git log --all -S "<the secret>" --oneline, which searches every commit on every branch for the point where that exact string entered or left the tree. Empty output means it never reached history and deleting it from the working tree is enough. Any output at all means the key is in your history and must be rotated first — rewriting history does not retrieve the clones, forks and CI caches that already have it.