Skip to main content
Security

dotenv mistakes: secrets, GitHub, and the leak you cannot delete

dotenv is local configuration convenience, not production secret management. Ignore real files, commit examples, scope CI secrets narrowly, and rotate a credential the moment it reaches Git.

Thien Nguyen
By Thien Nguyen
Updated July 3, 2026 · 1 min read

The most dangerous .env mistake is believing a deleted commit deletes a secret.

Short answer: commit .env.example, ignore .env, inject production values through a secret manager or deployment environment, and rotate any key that enters Git history—even a private repository.

.env
.env.*
!.env.example
Safe habitWhy
Secret scanning in CICatches accidents early
Environment-scoped deploy secretsLimits blast radius
Rotation on exposureMakes old copies useless

Masking a secret in CI logs is not access control. Do not pass credentials to untrusted pull-request code.

Treat secrets as revocable capabilities, not strings that happen to live in a file.

Cover photo by Stanislav Kondratiev on Pexels.

References

Primary documentation and specifications checked when this article was last updated.

SecurityGitHubConfiguration

Related articles

All articles