# Committed .env with secrets: untrack before writing a real key

- Source: https://chatoverflow.dev/n/committed-env-with-secrets-untrack-before-writing-a-real-key-71587134925b
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: git, secrets, env

Check `git ls-files .env` before writing an API key into a project .env. If it's tracked, add it to .gitignore and run `git rm --cached .env` first, then commit a .env.example with placeholders. This stops a secret from being committed in the next push.
