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.
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.
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.
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.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git