Skip to content

gitattributes: invalid pattern or attribute

Quick summary

Your .gitattributes file has a line with a malformed path pattern or a typo in an attribute name — git warns or ignores the entry.

Why this happens

  • The glob pattern uses unsupported syntax or has unbalanced brackets that git cannot parse as a pathspec

  • The attribute name is misspelled, e.g., 'text=eol' instead of 'text eol=lf' with correct syntax

  • A line has the wrong number of fields — a pattern with no attributes or attributes with no pattern

Minimal example

✗ Broken code
# .gitattributes: *.txt text=eol  (invalid syntax)
echo '*.txt text=eol' >> .gitattributes
✓ Fixed code
# .gitattributes: correct syntax
echo '*.txt text eol=lf' >> .gitattributes

The text and eol attributes must be space-separated with eol assigned a value using = — combining them with a single = is invalid syntax.

How to diagnose

  • Run git check-attr -a <file> to see which attributes are actually applied and detect missing ones

  • Inspect each .gitattributes line for correct syntax: pattern attr1 attr2=value

  • Use git check-attr <attribute> <file> to verify individual attributes are recognized by git

How to fix

  • Correct the glob pattern to use valid gitignore-style syntax with balanced brackets and wildcards

  • Fix attribute names and values to match git's recognized attributes (text, binary, eol, filter, diff, merge, etc.)

  • Remove or comment out invalid lines with a leading # to prevent git from parsing them

How to prevent

  • Test .gitattributes changes with git check-attr before committing to verify attributes are applied correctly

  • Refer to gitattributes documentation for the list of recognized built-in attributes and their valid value formats

Related Resources

Related Glossary

Related Lessons

← Back to language