
Stop Committing .env Files: A Proper .gitignore for Every Stack
If your first commit to a new repository does not include a .gitignore file, you are starting wrong. I have seen API keys pushed to public repos because someone forgot to ignore .env files. I have seen repositories bloated with node_modules, build artifacts, and IDE configuration that made cloning take 20 minutes. And once a file is in git history, removing it is painful even if you delete it later. A good .gitignore is your first line of defense against accidentally committing things that should not be in version control. What .gitignore does (and does not do) The .gitignore file tells git which files and directories to exclude from tracking. It uses glob patterns: # Ignore all .env files .env .env.* # Ignore node_modules directory node_modules/ # Ignore build output dist/ build/ # Ignore OS files .DS_Store Thumbs.db Critical caveat: .gitignore only prevents untracked files from being added. If a file is already tracked by git (it was committed before the .gitignore rule was added), t
Continue reading on Dev.to Beginners
Opens in a new tab




