How to fix warning: ignoring invalid gitattributes pattern in Git
Git warns that a pattern in your .gitattributes file uses invalid syntax and will be ignored. This typically occurs from using unsupported wildcards, brace expansion, or negative patterns.
Quick fix
Fixes warning: ignoring invalid gitattributes pattern
# View your .gitattributes file
cat .gitattributes
# Or use git check-attr to debug specific files
git check-attr -a path/to/file.txt- Identify the invalid pattern in .gitattributes
- Replace brace expansion with separate lines
- Fix directory patterns to use path/** syntax
- Remove negative patterns
# View your .gitattributes filecat .gitattributes# Or use git check-attr to debug specific filesgit check-attr -a path/to/file.txtwarning: ignoring invalid gitattributes pattern
What this error means
The .gitattributes file allows you to specify attributes for files matching certain patterns, controlling how Git handles line endings, diffs, merges, and more. Git uses pattern matching rules similar to .gitignore, but with important differences. When Git encounters a pattern it cannot parse or that uses unsupported syntax, it emits this warning and ignores the line entirely. This means the attributes you intended to apply won't take effect, potentially causing unexpected behavior with line ending conversions, language detection, or Git LFS tracking. Common causes include using brace expansion syntax (which works in shells but not in .gitattributes), attempting to use negative patterns (which are only valid in .gitignore), or misunderstanding how directory patterns work in attributes files.
Typical symptoms
- Warning message appears during git operations: "ignoring invalid gitattributes pattern"
- File attributes not being applied as expected
- Git LFS not tracking files that should match a pattern
- Line ending conversions not occurring for specified files
- Language detection or diff behavior differs from .gitattributes configuration
Common causes
- Using brace expansion syntax like *.{js,ts} which is not supported in .gitattributes
- Attempting to use negative patterns (starting with !) which only work in .gitignore
- Using trailing slash path/ syntax for directories instead of path/**
- Invalid wildcard combinations or unsupported glob patterns
- Special characters not properly escaped or quoted
- Mixing .gitignore syntax with .gitattributes syntax
- Including configuration-style syntax like [core] sections in .gitattributes
How to fix "warning: ignoring invalid gitattributes pattern"
Open your .gitattributes file and look for patterns mentioned in the warning message. Check each pattern against valid syntax rules.
# View your .gitattributes file
cat .gitattributes
# Or use git check-attr to debug specific files
git check-attr -a path/to/file.txtCommon invalid patterns to look for:
- Brace expansion: *.{ext1,ext2}
- Negative patterns: !*.log
- Directory trailing slash: docs/
- Invalid wildcards: **/ without a pattern
If you're using brace expansion, expand it into individual patterns:
# ❌ Invalid - brace expansion not supported
*.{js,ts} text eol=lf
# ✅ Valid - separate lines for each pattern
*.js text eol=lf
*.ts text eol=lfThis is the most common cause of invalid pattern warnings.
Directory patterns behave differently in .gitattributes than in .gitignore. Use the recursive wildcard syntax:
# ❌ Invalid - trailing slash is pointless in .gitattributes
docs/ linguist-documentation
# ✅ Valid - use /** for recursive directory matching
docs/** linguist-documentation
# ✅ Also valid - match all files in docs and subdirectories
docs/* linguist-documentationRemember: patterns matching a directory don't recursively match paths inside it.
Negative patterns (starting with !) are not supported in .gitattributes. Remove them or restructure your attributes:
# ❌ Invalid - negative patterns not allowed
*.log text
!important.log
# ✅ Valid - use explicit patterns for exceptions
*.log text
important.log binaryLater patterns override earlier ones, so place exceptions after general rules.
After fixing patterns, test them to ensure they match the intended files:
# Check attributes for specific files
git check-attr -a src/app.js
git check-attr text src/app.js
# Check multiple files
git check-attr -a src/*.js
# Verbose output showing which .gitattributes line matched
git check-attr -v text src/app.jsThis helps verify your patterns are working correctly.
Changing .gitattributes won't retroactively fix files already in the repository. Force Git to re-apply attributes:
# Remove all files from the index
git rm --cached -r .
# Re-add all files (applies new attributes)
git add .
# Check what changed
git diff --cached
# Commit the attribute changes
git commit -m "Fix .gitattributes patterns and re-normalize files"⚠️ This creates a large commit touching many files. Coordinate with your team before doing this on shared branches.
Advanced notes
Pattern Matching Rules
.gitattributes uses the same pattern rules as .gitignore with key exceptions:
- No special-case directory handling (directories are not stored by Git)
- Later patterns override earlier patterns on a per-attribute basis
- Patterns are matched against the full path from repository root
Valid Wildcards:
- * matches zero or more characters (including /)
- ? matches exactly one character
- [abc] matches one character from the set
- ** matches zero or more directories
Attribute Precedence:
Git checks attributes in this order (highest to lowest precedence):
1. /info/attributes (repository-specific, not versioned)
2. .gitattributes in the same directory as the file
3. .gitattributes in parent directories (closer = higher precedence)
4. /info/attributes (global configuration)
Common Use Cases:
# Line ending normalization
*.sh text eol=lf
*.bat text eol=crlf
# Binary files
*.png binary
*.jpg binary
# Git LFS tracking
*.psd filter=lfs diff=lfs merge=lfs -text
# Language detection override
*.md linguist-detectable
docs/** linguist-documentation
# Diff drivers
*.json diff=json
*.ipynb diff=ipynbDebugging with GIT_TRACE:
For deeper debugging, use Git tracing:
GIT_TRACE=1 git check-attr -a file.txtThis shows which .gitattributes files Git is reading and how patterns are evaluated.
Frequently asked questions
- What does "warning: ignoring invalid gitattributes pattern" mean?
- gitattributes file allows you to specify attributes for files matching certain patterns, controlling how Git handles line endings, diffs, merges, and more. gitignore, but with important differences. When Git encounters a pattern it cannot parse or that uses unsupported syntax, it emits this warning and ignores the line entirely.
- How do I fix "warning: ignoring invalid gitattributes pattern"?
- Git warns that a pattern in your .gitattributes file uses invalid syntax and will be ignored. This typically occurs from using unsupported wildcards, brace expansion, or negative patterns.
- What causes "warning: ignoring invalid gitattributes pattern"?
- Using brace expansion syntax like *.{js,ts} which is not supported in .gitattributes Attempting to use negative patterns (starting with !) which only work in .gitignore Using trailing slash path/ syntax for directories instead of path/**
- Is the "warning: ignoring invalid gitattributes pattern" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Git Official Documentation
- 📖Docs: gitattributes patterns(Official Docs)