Should I commit my .env file to GitHub?
A .env file is a settings file where an app keeps its keys, which are long passwords it uses to prove who it is to other services. To commit is to save a change into your repository, the folder that holds your app's code and its history. The Next.js documentation notes that the default project template adds .env files to .gitignore, and that you almost never want to commit them.
GitHub secret scanning looks through your Git history for credentials and alerts you, but prevention is simpler. If a secret was committed, replace it: make a new one and turn the old one off. GitHub says to rotate an affected credential immediately.
A quick check: open your repository on GitHub and search for the file name .env. If it shows up, replace every key inside it, add the file name to .gitignore, and stop tracking it so it does not come back with the next save.
Sources
- Next.js documentation, Environment variables, accessed 2026-11-16
- GitHub documentation, About secret scanning, accessed 2026-11-16
See what your live app shows strangers
Paste the link to your app: in under a minute the free scan shows what your live app hands to any visitor, and where to look first. No sign-up, and it never signs in or changes anything.
Want the code itself read? Order the $49 audit or see a sample report. Your card is held and charged only when your report is delivered. It is not a pentest: the audit is done by AI, and a second AI checks each serious finding.