Skip to main content
⚡ OpenDevDocs
Git
gitgitGuideBeginner

Configuring .gitignore

How .gitignore works: glob patterns, ignoring node_modules and .env secrets, untracking previously committed files, and global gitignore.

Verified: 2026-09-30
Platforms:
all
#git#gitignore#configuration#secrets#security

Configuring .gitignore

A .gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected.


1. Standard Production .gitignore Template (Node/Next.js)

# Dependencies
node_modules/
.pnpm-store/

# Local Environment & Secrets
.env
.env*.local
*.pem
*.key

# Build outputs
.next/
dist/
out/
build/

# OS and Editor metadata
.DS_Store
Thumbs.db
.vscode/*
!.vscode/settings.json
!.vscode/launch.json

2. .gitignore Pattern Syntax

PatternBehaviorExample
filenameIgnores file anywhere in repositorysecret.key
/dir/Ignores directory relative to location of .gitignore/dist/
*.logGlob wildcard matching all .log filesdebug.log, app.log
!important.logNegation: Tracks important.log even if *.log was ignored!important.log
logs/**/err.txtRecursively matches nested directorieslogs/2026/09/err.txt

3. Untracking Files Already Committed to Git

If a sensitive file or node_modules/ was committed to Git before you added it to .gitignore, Git will continue tracking it until you remove it from the index:

# Remove from Git index while preserving file on local disk:
git rm --cached sensitive-config.json

# Or untrack an entire directory:
git rm -r --cached node_modules/

# Commit the removal:
git commit -m "chore: remove tracked node_modules from Git index"

On this page