Git attributes let us specify how files should be handled during staging and checkout. They can be expressed via .gitattributes files throughout the tree and are scoped to children of the immediate parent directory.

Listing attributes

List attributes set for the specified files:

git check-attr [-a|ATTR...] -- [PATH]

Note that the -- delimiter is necessary when specifying multiple attribute names; without it all arguments after the first argument are treated as paths.

Text vs binary

Git can be coerced into treating what are technically text files but are practically not mergeable as binary:

# This is definitely a bad idea, use `npm-merge-driver` instead
package-lock.json binary

Easing diffing files

The diff effect allows developers to diff a textual representation of binary files or complex/noisy text files.

The following attribute configuration:

*.json diff=json

Would invoke this configured diff driver:

[diff "git"]
  command = "json_pp <\"$1\""

For binaries, use textconv instead, which is applied only during git diff and git log:

[diff "jpeg"]
  textconv = exif

Merge drivers

Merge drivers similarly influence the merging process, letting you define custom behaviours for file merging. The following substitutions are available for the driver command:

  • %A: current version.
  • %O: common ancestor's version.
  • %B: other branch's version.
  • %P: destination path.

Line endings

Some tools, particularly Visual Studio with its solution and project files, are picky about line endings:

*.sln text eol=crlf
*.csproj text eol=crlf

eol can be set to either lf or crlf:

  • lf forces forces Git to normalise line endings to LF on checkin and prevents conversion to CRLF on checkout.
  • crlf forces Git to normalise line endings to LF on checkin and convert them to CRLF on checkout.


Filters each provide two commands, defined as values in a filter section:

[filter "my-filter"]
  clean = my-filter --clean
  smudge = my-filter --smudge

The clean filter removes local changes ahead of checkin, and the smudge filter can be used to apply local changes on checkout.