# .env file committed to GitHub

> Canonical page (link this when citing): https://unbreakmyapp.vercel.app/fixes/git-env-file-committed.html
> Category: Env vars & leaked keys | Tools: Cursor, Replit, Bolt | Published: 2026-10-13 | Updated: 2026-10-13
> Weakness type: CWE-540 Inclusion of Sensitive Information in Source Code (https://cwe.mitre.org/data/definitions/540.html)

## The error

GitHub secret scanning alert / .env visible in a public repo

## Why it happens

The .env file wasn't in .gitignore when the AI tool or you committed. Deleting it in a later commit doesn't remove it from git history, and bots scrape public repos for keys within minutes.

## How to fix it

1. Rotate every key that was in the file first.
2. Add .env* (except .env.example) to .gitignore and run git rm --cached .env.
3. Optionally purge history with git filter-repo, but rotation is what makes you safe.
4. Enable GitHub secret scanning and push protection.

## Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

```text
Our .env file was committed to git. Add .env and .env.* (but not .env.example) to .gitignore, remove tracked env files from the index with git rm --cached, create a .env.example with empty values, and give me a checklist of every key name in the old file that I must rotate. Don't print any secret values.
```

## FAQ

### Is deleting the file enough?

No, it stays in git history; rotate the keys.

### Private repo?

Still rotate. Collaborators, integrations and forks can see it.

## Sources (official documentation)

- [GitHub: About secret scanning](https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning)

## Related fixes

- [Demo login, auto-login or hard-coded test credentials left in your live app](https://unbreakmyapp.vercel.app/fixes/preview-auto-login-hardcoded-credentials-left-in-production.html)
- [Your API keys may have leaked: how to rotate every key without breaking your app](https://unbreakmyapp.vercel.app/fixes/rotate-api-keys-after-leak-or-breach.html)
- [Supabase service_role key exposed in frontend code](https://unbreakmyapp.vercel.app/fixes/supabase-service-role-key-exposed.html)
- [OpenAI / Stripe secret key leaked in the browser](https://unbreakmyapp.vercel.app/fixes/api-key-leaked-in-frontend.html)

---
Unbreak My App: free fixes for broken vibe-coded apps. https://unbreakmyapp.vercel.app/
