DeveloperApril 2026 ยท 5 min read

How to Create a .gitignore File (2026)

A .gitignore file is one of the first things you should create in any new repository. Without it, Git tracks everything โ€” node_modules, compiled binaries, .env secrets, IDE configuration, OS junk files, and build artifacts. Your repository bloats, secrets leak, and collaborators deal with merge conflicts in files they never touch.

๐Ÿšซ
Try the .gitignore Generator
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01Pattern Syntax02Language-Specific Rules03Common Mistakes04Global .gitignore
โšก Key Takeaways
  • Covers pattern syntax.
  • Covers language-specific ignore rules.
  • Covers common .gitignore mistakes.
  • Covers global .gitignore for your machine.

Pattern Syntax

Glob patterns: * matches any characters within a filename (*.log ignores all log files). ** matches across directories (**/test ignores test directories at any depth). ? matches a single character.

Directory trailing slash: build/ ignores the entire build directory and everything in it. Without the slash, build would match both files and directories named build.

Negation: ! re-includes a previously ignored pattern. If you ignore *.log but want to keep important.log, add !important.log after the *.log rule. Order matters โ€” negation must come after the ignore rule.

Language-Specific Ignore Rules

Node.js: always ignore node_modules/ (it can contain 100,000+ files), dist/ and build/ (compiled output), .env (secrets), *.log, and coverage/ (test coverage reports). node_modules alone can be hundreds of megabytes.

๐Ÿ’ก Tip
Always include -webkit-backdrop-filter alongside backdrop-filter for Safari support. Without the prefix, the effect is invisible to roughly 25% of mobile users.

Python: ignore __pycache__/, *.pyc, *.pyo (compiled bytecode), venv/ or env/ (virtual environments), .egg-info/, dist/, build/, and .pytest_cache/. Virtual environments should be recreated from requirements.txt, never committed.

React: in addition to Node.js patterns, ignore .env.local, .env.development.local, .env.test.local, and .env.production.local. Create React App generates these environment-specific files locally.

Common .gitignore Mistakes

Adding .gitignore too late: if files are already tracked by Git, adding them to .gitignore does not untrack them. You need to run git rm --cached filename to remove them from tracking first.

โš  Warning
On iOS Safari, backdrop-filter inside a position: fixed element can cause severe scroll performance issues. Test thoroughly on real iOS devices.

Ignoring too much: if your .gitignore is overly aggressive, important files might be missing from the repository. After creating .gitignore, verify with git status that the right files are being tracked.

Not ignoring enough: IDE settings (.idea/, .vscode/), OS files (.DS_Store, Thumbs.db), and editor swap files (*.swp, *~) should always be ignored. These are machine-specific and cause unnecessary conflicts.

Global .gitignore for Your Machine

Your personal machine generates files that should never be in any repository: .DS_Store (macOS), Thumbs.db (Windows), .idea/ (JetBrains IDEs), .vscode/ (VS Code). Rather than adding these to every project, create a global .gitignore.

Set it up with git config --global core.excludesfile ~/.gitignore_global. Then add OS and IDE patterns to that file. This keeps project .gitignore files focused on project-specific patterns.

Global gitignore handles your environment. Project gitignore handles the project. This separation means team members using different OSes and editors do not need to coordinate their ignore rules.

Frequently Asked Questions

What if I already committed files I want to ignore?+
Add the patterns to .gitignore, then run git rm --cached to untrack them. The files stay on disk but Git stops tracking them.
Should I commit .gitignore?+
Yes. .gitignore should be committed so all team members share the same ignore rules. It is one of the first files in any repository.
Does .gitignore affect already-committed files?+
No. .gitignore only prevents untracked files from being added. Files already in Git history remain tracked until explicitly removed with git rm --cached.
Can I have multiple .gitignore files?+
Yes. Each directory can have its own .gitignore with rules scoped to that directory and its subdirectories. Rules are cumulative.
Try it yourself

Generate .gitignore for your stack โ€” free, no signup.

โšก Open .gitignore Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.