What Is .gitattributes and What Is It For?
A .gitattributes file lets you define path-specific attributes that control how Git handles certain files, most commonly line-ending normalization.
Published September 29, 2026
A .gitattributes file defines per-path settings for Git, such as line-ending normalisation, diff behaviour, binary files, merge strategies and Git LFS rules.
How it works
It lives in the repository so every collaborator gets the same behaviour regardless of local configuration.
The most common use is fixing line endings across Windows and Unix.
Try it
cat .gitattributes
* text=auto
*.png binary
*.lock -diff
Practical examples
Normalise line endings
* text=auto eol=lf
*.bat text eol=crlfMark binaries
*.png binary
*.pdf binaryGit LFS
*.psd filter=lfs diff=lfs merge=lfs -textLanguage statistics override on GitHub
vendor/* linguist-vendoredCommon mistakes
- CRLF/LF noise in diffs because it is missing.
- Forgetting to run git add --renormalize . after changes.
- Marking text files as binary.
Key takeaways
- Per-path Git behaviour in the repo.
- Fixes line endings.
- Also configures LFS and diff drivers.
FAQ
Where do I put it?
Repository root (or subfolders).
Does it replace .gitignore?
No, .gitignore decides what is tracked; .gitattributes decides how.