Gitattributes
_Git · Reference cheat sheet_
Gitattributes
Git · Reference cheat sheet
📖 Overview
.gitattributes assigns attributes to paths: line-ending normalization, diff/merge drivers, linguist overrides, and Git LFS filters. Keep it committed so every clone behaves the same.
🧩 Core concepts
text/eol— normalize LF in the repo; checkoutlforcrlfper path.binary— skip text conversion/diff for binaries.diff/merge— custom drivers for generated or vendor files.export-ignore— omit paths fromgit archive.- Linguist —
linguist-language,linguist-vendored,linguist-generatedfor GitHub stats. - LFS filter —
filter=lfs diff=lfs merge=lfs -textfor large files.
💡 Examples
# Normalize text; force LF in working tree for these
* text=auto eol=lf
*.sh text eol=lf
*.bat text eol=crlf
*.ps1 text eol=lf
# Binaries
*.png binary
*.jpg binary
*.pdf binary
*.zip binary
# Generated / vendored (GitHub Linguist)
dist/** linguist-generated=true
vendor/** linguist-vendored=true
# Custom diff for lockfiles (optional)
package-lock.json -diff
pnpm-lock.yaml -diff
# LFS (after git lfs track)
*.psd filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
# Archives
docs/internal/** export-ignore# Refresh working tree after attributes change
git add --renormalize .
git status⚠️ Pitfalls
- Changing
eolmid-project causes huge diffs unless you renormalize carefully. - Marking text as
binaryhides useful diffs and can complicate merges. - LFS patterns belong here and need
git lfs installon each machine. - Attributes are path-based — rename/move files can drop intended rules if patterns are too narrow.