Updated June 29, 2026
.gitignore patterns reference
A .gitignore file tells Git which files to leave untracked. Patterns match by name, path, and wildcards. Copy any pattern or the starter block below.
Syntax
| Pattern | What it ignores |
|---|---|
*.log | Every file ending in .log. |
build/ | A directory named build and its contents. |
/secret.txt | secret.txt only in the repo root. |
**/temp | A temp folder at any depth. |
!keep.log | Negation: do not ignore keep.log. |
# comment | A comment line, ignored by Git. |
Commonly ignored
| Pattern | What it ignores |
|---|---|
node_modules/ | Installed npm dependencies. |
.env | Environment files with secrets. |
dist/ | Build output. |
.DS_Store | macOS folder metadata. |
*.tmp | Temporary files. |
.idea/ | JetBrains IDE settings. |
.vscode/ | VS Code workspace settings. |
coverage/ | Test coverage reports. |
Snippet: a Node starter .gitignore
A reasonable starting point for a Node or web project.
node_modules/
dist/
build/
coverage/
.env
.env.local
.DS_Store
*.logAlready-tracked files keep being trackedAdding a pattern does not untrack a file Git already knows about. Run
git rm --cached <file> to stop tracking it, then commit.References
Questions
Why is node_modules still tracked after I added it to .gitignore?
gitignore only affects untracked files. If node_modules was already committed, remove it from the index with git rm -r --cached node_modules and commit the change.
How do I ignore everything except one file?
Ignore broadly, then re-include with a negation. For example, * on one line and !keep.txt on the next keeps only keep.txt.