A .gitignore file lists patterns for untracked files Git 1,932 should leave alone. Create it in the repository root:
# Dependencies: npm ci recreates them from package-lock.json
node_modules/
# Secrets and local settings: commit only the example file
.env
.env.*
!.env.example
# Logs, coverage and runtime files
*.log
coverage/
*.pid
# Operating-system clutter
.DS_Store
Thumbs.dbA trailing / matches directories only, * matches within one path component, a leading / anchors a pattern to the directory holding the .gitignore, and ! re-includes something an earlier line excluded. git check-ignore -v tells you which rule decides a path:
printf 'PGPASSWORD=booknest\n' > .env
git check-ignore -v .env node_modules/express/package.json server.log .env.example.gitignore:5:.env .env .gitignore:2:node_modules/ node_modules/express/package.json .gitignore:10:*.log server.log .gitignore:7:!.env.example .env.example
Each line gives the file, line number and pattern that matched; a match on a ! pattern means the path is not ignored, so .env.example can be committed. Ignore rules affect only untracked files: a file already committed stays tracked whatever .gitignore says (Cleaning the Tree). Personal patterns go in .git/info/exclude or a global ignore file (Global Ignore Files). Start new projects from the templates at github.com/github/gitignore (https://github.com/github/gitignore 175,955 ).