Why .env must be in .gitignore (and how to check it is not already committed)
Why it matters
A .env file collects every secret the application needs in one place. Without a .gitignore rule, one `git add .` publishes all of them at once.
How to fix it
What to do: Add
If
.env and other secret files to .gitignore.# Environment files
.env
.env.local
.env.*.local
*.env
# Keys and secrets
*.pem
*.key
credentials.json
If
.env was already committed: git rm --cached .env.Does your repository pass this check?
Free for public GitHub repositories, no account needed. 50+ DevOps and security checks in about ten seconds.
Public repositories where this check fails
Related checks
- How to find and remove secrets committed to a Git repository
- A .env file is committed to the repository: what to do
- Automated dependency updates with Dependabot or Renovate
- How to pin GitHub Actions to a commit SHA
- Least-privilege GITHUB_TOKEN permissions in workflows
- The pull_request_target trap in GitHub Actions