Skip to content

attributes Git Command Guide

Git attributes provide configuration options for how Git handles files in the repository through the .gitattributes file. Attributes can control text/binary treatment, diff/merge behavior, and export settings for individual files or patterns.

git check-attr Syntax (to query attributes):

Section titled “git check-attr Syntax (to query attributes):”
Terminal window
git check-attr [--source=<tree>] [-a|--all] [--] <name> <file>
OptionDescription
-a, —allList all attributes set for specified files
—source=Check attributes in instead of working tree
—cachedCheck .gitattributes cached by Git
—stdinRead filenames from stdin
ParameterDescription
nameAttribute name to check (e.g., text, diff, merge)
fileFile(s) to check attributes for

git attributes Command Samples (using git check-attr):

Section titled “git attributes Command Samples (using git check-attr):”
Terminal window
git check-attr text myfile.txt

Shows whether myfile.txt is marked as text.

Terminal window
git check-attr --all myfile.txt

Displays all attributes set for myfile.txt.

Terminal window
git check-attr --source=HEAD^ text myfile.txt

Queries attributes as they were in the parent commit.

Terminal window
git check-attr text -- *.txt

Checks text attribute for all .txt files.

How do I check if a file has a specific attribute set in Git?

Section titled “How do I check if a file has a specific attribute set in Git?”

To check if a file has a specific attribute set, use git check-attr followed by the attribute name and file name:

Terminal window
git check-attr <attribute> <file>

How can I view all attributes set for a file?

Section titled “How can I view all attributes set for a file?”

To view all attributes set for a file, run:

Terminal window
git check-attr --all <file>

How do I check attributes for multiple files at once?

Section titled “How do I check attributes for multiple files at once?”

To check attributes for multiple files, use:

Terminal window
git check-attr <attribute> <file1> <file2> ...

How can I check attributes as they were in a past commit?

Section titled “How can I check attributes as they were in a past commit?”

To check attributes as they were in a past commit, execute:

Terminal window
git check-attr --source=<commit> <attribute> <file>

How do I use git attributes to ignore files during export?

Section titled “How do I use git attributes to ignore files during export?”

To ignore files during export, add the export-ignore attribute in .gitattributes:

secret.txt export-ignore

Applications of the git attributes feature

Section titled “Applications of the git attributes feature”
  1. Configuring text/binary handling for specific file types
  2. Setting custom diff or merge drivers for files
  3. Ignoring files during git archive exports
  4. Controlling end-of-line conversions across platforms
  5. Using external tools for specific file patterns
  6. Managing language-specific behavior for source files