G
GitIgnore.pro

Advanced .gitignore Patterns

Master sophisticated .gitignore techniques for complex projects. Learn regex patterns, advanced wildcards, negation rules, and performance optimization strategies.

Expert Level Content

This guide covers advanced techniques. Ensure you're comfortable withbasic .gitignore usagebefore proceeding.

🎯 Pattern Complexity Mastery

1Advanced Wildcard Patterns

🌟 Sophisticated Matching

Character Classes:
# Match any single digit
file[0-9].txt
# Match any letter
temp[a-z].log
# Match specific characters
backup[123].sql
# Negated character class
data[!0-9].csv
Multiple Extensions:
# Multiple extensions
*.log
*.tmp
*.cache
*.bak
# Multiple prefixes
debug_*.txt
test_*.txt
temp_*.txt

⚡ Performance Examples

✅ Efficient
# Specific and targeted
src/**/*.test.js
logs/[0-9][0-9][0-9][0-9]/*.log
❌ Inefficient
# Too broad, slows Git
**/*.*
**/[a-z]*/**/*

2Advanced Negation Techniques

⚠️ Negation Order Matters

Git processes .gitignore patterns sequentially. Negation patterns must come AFTER the patterns they override.

✅ Correct Order
# Ignore all logs first
*.log
# Then allow important.log
!important.log
# Ignore temp directory
temp/
# But keep temp/keep.txt
!temp/keep.txt
❌ Wrong Order
# Won't work - negation first
!important.log
*.log
# Won't work - directory ignored
!temp/keep.txt
temp/

🎯 Complex Negation Scenarios

Scenario: Ignore all config files except production
# Ignore all config files
config/*.json
# Keep production configs
!config/production.json
!config/prod-*.json
Scenario: Ignore build outputs but keep documentation
# Ignore entire build directory
build/
# Keep documentation in build
!build/docs/
!build/**/*.md
# But ignore temp docs
build/docs/temp/