Progress:
TIER 2 · MODULE 40· Intermediate

git check-attr

Why is this file being treated like text? This tells you.

🎯 What & why

Tells you which .gitattributes rules apply to a given path. The answer to 'why is git treating this file as text/binary/whatever?'.

🧠 Mental model

Think of it as a query tool against the attribute resolution engine. Same precedence as the actual checkout uses: per-directory .gitattributes, then $GIT_DIR/info/attributes, then global. check-attr just reports the result.

🛠️ Synopsis

git check-attr [-a | <attr>...] [--cached] [-z] [--stdin] [--] <pathname>...

Output format:
  <path>: <attr>: <value>
where <value> is set | unset | unspecified | <string>

🎚️ Switches & options

FlagWhat it does
-a, --allShow every attribute defined for the path. Don't pass attrs explicitly.
--cachedUse attributes from the index, not the working tree (matches what checkout/diff sees in CI).
--stdinRead paths from stdin. Pair with -z for NUL-separated paths.
-zNUL-separate input and output. Use whenever paths could contain newlines.
<attr>...Specific attributes to query (e.g. text eol diff). Faster than -a.

💡 Use cases

🧪 Examples

Show every attribute on a file
git check-attr -a path/to/file.c
Check specific attributes
git check-attr text eol diff README.md
Bulk audit all tracked paths
git ls-files -z | git check-attr --stdin -z -a
What does CI see?
git check-attr --cached -a generated/output.bin

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.