Create a .gitignore that keeps node_modules, build output, local environment files, and editor clutter out of your Git commits.
Let's think about it this way for a sec
.gitignore is a list of rules telling Git 'don't track these file patterns.' Folders you can reinstall, like node_modules, output you can rebuild, like .next or dist, and files that might contain secrets, like .env.local, shouldn't be committed to the repository. Lockfiles, though, should be committed so you get exact dependency versions back. But having a .gitignore alone doesn't make your secrets safe — a new ignore rule can't retroactively untrack a file Git is already tracking.
Connecting it to everyday life
Create a .gitignore in the project root and add patterns that match your stack. For .env.example, you can commit it with just the key names and fake or blank values. Check git status again to confirm node_modules, .next, dist, and .env.local no longer show up. If a secret has ever been committed, deleting the file isn't enough — you need to revoke/rotate the key.
Let's try it together
# Dependencies
node_modules/
# Build output
.next/
dist/
coverage/
# Local environment files
.env
.env.local
.env.*.local
# Editor / operating system
.vscode/
.DS_Store
Thumbs.dbYou'll have a .gitignore that fits your project, and secrets, dependencies, and generated output will no longer end up in your commits.5-Minute Try-It
Adapt the sample .gitignore to your own stack. Then check git status again to confirm files that should be ignored no longer appear.
A Quick Word of Caution
Never treat AI output as automatically correct. Have a human read through the code and test it — and double-check secrets and user data — before you rely on it.