Why git ignores secrets
Once a file reaches GitHub, it is public. Anyone, including bots that scan for keys, can read it.
A .env file usually holds every secret your app needs. If one is committed, the damage is done even before you notice. That is why the rule is simple:
- Put secrets in
.env. - Add
.envandnode_modulesto.gitignore. - Commit only code, never secrets.
This one habit has prevented real breaches. Make it automatic so you never have to remember.