.gitignore Generator Guide: Quickly Create Ignore Rules by Project Type

Utilities(Updated Jun 20, 2026)

What Is .gitignore

The .gitignore file tells Git which files/directories should not be version-controlled:

node_modules/       ← Ignore entire directory
*.log               ← Ignore all log files
.env                ← Ignore environment variable file
dist/               ← Ignore build output

Untracked files matching .gitignore rules are automatically skipped by Git. Already-tracked files are not affected.


Syntax Rules Explained

Basic Patterns

Syntax Meaning Example
*.ext Match all .ext files *.log
dir/ Match entire directory node_modules/
file Match specific file .env
** Match any directory level **/test
? Match single character config?.json
[abc] Match any character in brackets file[123].txt

Negation Pattern !

*.log           ← Ignore all logs
!important.log  ← But keep important.log

Negation patterns must be placed after the ignore rule they negate.

Path Rules

/README.md      ← Ignore only root-level README.md
README.md       ← Ignore README.md at any level
docs/*.pdf      ← Ignore PDFs in docs/, non-recursive
docs/**/*.pdf   ← Ignore PDFs in all subdirectories of docs/

Common Project Templates

Node.js

node_modules/
dist/
build/
.next/
.env
.env.local
*.log
coverage/

Python

__pycache__/
*.py[cod]
*.egg-info/
dist/
.venv/
venv/
.env
.pytest_cache/
.mypy_cache/

Java / Spring Boot

target/
*.class
*.jar
*.war
.gradle/
.idea/
*.iml
application-local.yml

IDE / Editors

# VS Code
.vscode/

# IntelliJ IDEA
.idea/
*.iml

# macOS
.DS_Store

# Windows
Thumbs.db

Using the gitignore Tool

Step 1: Open the Tool

Visit the gitignore tool to enter the generator interface.

Step 2: Select Project Type

Check the tech stack used in your project:

  • ☑ Node.js
  • ☑ Python
  • ☑ Java
  • ☑ Vue / React / Angular

Step 3: Select IDE

Check the editors used by your team:

  • ☑ VS Code
  • ☑ IntelliJ IDEA
  • ☑ Other

Step 4: Generate and Download

Click "Generate". The tool automatically merges all templates, removes duplicates, and produces a complete .gitignore file.

Step 5: Place in Project Root

Put the downloaded file in your Git repository root. Make sure the filename is .gitignore (note the leading dot).


Global gitignore

Besides project-level .gitignore, you can set global ignore rules (applies to all repos):

# Set global gitignore file
git config --global core.excludesFile ~/.gitignore_global

# Edit global rules
vim ~/.gitignore_global

Recommended global ignores:

# OS files
.DS_Store
Thumbs.db

# IDE configs
.idea/
.vscode/

# Personal tools
.todo

Global rules are for personal environment files. Project-level rules are for project-specific files.


Handling Already-Tracked Files

.gitignore only affects untracked files. If a file is already tracked by Git:

# Untrack but keep the local file
git rm --cached .env

# Untrack an entire directory
git rm -r --cached node_modules/

# Commit the untracking change
git commit -m "chore: update gitignore and untrack files"

The --cached flag ensures removal from the Git index only, without deleting the local file.


Common Mistakes

Mistake Cause Solution
Rule not working File already tracked Run git rm --cached first
Negation not working ! placed before ignore rule Move ! rule after the corresponding ignore rule
Ignored too much Pattern too broad Use / to limit path scope
Forgot to ignore .env Missing env var template Always add .env to .gitignore
Team rules inconsistent No unified template Use the tool to generate a standard template

.gitignore and .gitkeep

After ignoring a directory, Git won't track empty directories. To preserve empty directory structure:

logs/           ← .gitignore ignores logs
logs/.gitkeep   ← .gitkeep placeholder, preserves directory

.gitkeep is not a Git feature—it's a community convention. Place a .gitkeep file in the empty directory.


Summary

.gitignore is fundamental to project configuration. Correct ignore rules prevent committing sensitive information and redundant files. Master the syntax, common templates, and global configuration, and use the gitignore tool for quick generation—it's the first step to effective version control.

#gitignore#Git#忽略规则#项目配置#版本控制