Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Plumbing Commands

git check-attr command

Reference for git check-attr: display the .gitattributes values that apply to a path, query one or all attributes, and read set, unset, unspecified and value states.

git check-attr shows which attributes apply to a path. Attributes come from .gitattributes files (and .git/info/attributes) and control how Git treats files: line endings, diff and merge drivers, filters, export rules and more. When a file behaves unexpectedly, check-attr tells you what Git actually concluded after combining all the pattern lines.

Each line of output has the form path: attribute: info, where info is set, unset, unspecified or the assigned value.

Terminal
git check-attr text eol -- notes.txt
git check-attr -a -- notes.txt

Try it

Bash Query named attributes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash All attributes, the -z form, and a stdin list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git check-attr [-a | --all | <attr>...] [--cached] [-z] [--] <pathname>...
git check-attr --stdin [-z] [-a | --all | <attr>...]
Name Description
<attr>... Attribute names to look up. Required unless -a is used.
<pathname>... Paths to inspect. They do not need to exist.
-a, --all List every attribute that is set, unset or has a value for each path (unspecified ones are not shown).
--cached Read .gitattributes from the index, not from the working tree.
--stdin Read paths from standard input.
-z NUL-terminated input and output.
--source=<tree-ish> Read attributes from a tree instead of the work tree (Git 2.40 and newer).

Output: <path>: <attribute>: <info> per pair, where <info> is:

State Meaning
set Written as attr (no value).
unset Written as -attr.
<value> Written as attr=value.
unspecified No pattern says anything about it.

Exit status: 0 on success, non-zero on a usage error. A path with no attributes is not an error.

Usage notes

  • Use -- before the paths when the first path could be mistaken for an attribute name, as in git check-attr text -- text.
  • Macros expand. binary is a built-in macro for -diff -merge -text, so a path marked binary shows those three attributes as unset. User-defined macros ([attr]name ...) behave the same way.
  • Precedence: later lines override earlier ones, and a .gitattributes in a subdirectory overrides its parent for files below it. .git/info/attributes wins over both.
  • Patterns differ from .gitignore: a trailing slash does not match a directory in attribute patterns, and negative patterns are not supported.
  • Cannot show the cause. Unlike check-ignore -v, the command does not report the file and line; search the .gitattributes files yourself.
  • Bare repositories read attributes from info/attributes and, since 2.40, from --source or the attr.tree configuration.
  • Normalisation check: pair text eol output with git ls-files --eol to see what is stored and what is on disk.