Why .env must be in .gitignore (and how to check it is not already committed)

.env is ignored by git · security.env_gitignored

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 .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