What a .gitignore does
A .gitignore file tells Git which files to skip, keeping build output, dependencies, editor settings and secrets out of your repository. Committing those files bloats the repository and can leak credentials, so a good ignore file is part of every healthy project.
The patterns that matter
| Pattern | Meaning |
|---|---|
| node_modules/ | A directory and everything inside it |
| *.log | Any file ending in .log |
| !important.log | Un-ignore a previously matched file |
| .env | Your secrets file |
| build/ | Build output directory |
Always ignore your secrets
The most important entry is .env. Committing it exposes API keys and passwords to anyone who can read the repository, and scrapers find them within minutes. Ignore the real file and commit a redacted example instead. The .env File Generator produces a safe starting point.
Generate instead of guessing
Rather than memorising patterns for every language and editor, tick the stacks you use in the .gitignore Generator and copy the result. Add project-specific rules by hand as your setup grows.
Already committed a file?
Adding a path to .gitignore only affects untracked files. If something is already tracked, run git rm --cached path to stop tracking it, then commit. The file stays on disk but leaves the repository - exactly what you want for build output and local configuration.
A quick checklist
- Dependencies and package caches
- Build and coverage output
- Logs and temporary files
- Editor and OS junk files
- Environment and secret files
Cover those five categories and your repository stays clean and safe.