Lesson 43 +20 XP

Git .gitattributes

Git .gitattributes

A .gitattributes file sets rules for how Git handles specific file types in your repository.

Create the file

Place it in your repository root:

.gitattributes

Common uses

  • Line endings: force consistent line endings between Windows and Unix.
  • Diff settings: tell Git how to compare certain file types.
  • Merge drivers: custom merge behavior for special files.
  • LFS: mark large file types to use Git LFS.

Example: line endings

* text=auto
*.sh text eol=lf
*.bat text eol=crlf

This keeps shell scripts with Unix line endings and batch files with Windows endings.

Example: binary files

*.png binary
*.jpg binary

Marking files as binary tells Git not to try text diffs on them.

Example: mark files for LFS

*.psd filter=lfs diff=lfs merge=lfs -text

This routes Photoshop files through Git LFS.

Pattern syntax

Patterns work like .gitignore: matches any file, and you list extensions like .png.

TL;DR

  • .gitattributes controls how Git handles specific file types.
  • Common uses: line endings, binary files, diff rules, and LFS.
  • Patterns look like .png or .sh.
  • It is committed to the repo so everyone uses the same rules.