What is .gitattributes?
Git tracks files..gitattributes tells Git how to behave around them.
Git doesn’t just store files — it can be instructed how to treat them.
Line endings.
Diffs.
Merges.
Exports.
That’s exactly what .gitattributes is for.
A .gitattributes file lets you define rules for how Git handles specific
files or paths in your repository.
Get Qasim-AJ’s stories in your inbox
Join Medium for free to get updates from this writer.
Think of it as configuration for file behavior, stored inside the repo,
so everyone on the team plays by the same rules.
Example rules
# Use Unix line endings for all text files
*.txt text eol=lf
# Treat lock files as binary (no diffs or merges)
*.lock binary
# Ensure shell scripts always use LF
*.sh text eol=lfExample project structure
project/
├── .gitattributes
├── entry-point.sh
├── README.txt
├── package.lock
└── src/
└── main.jsHow this applies
README.txtwill always use LF line endings — even on Windowsentry-point.shwon’t break due to CRLF issues in Docker or CIpackage.lockwon’t generate noisy or meaningless diffs
Common uses of .gitattributes
- Enforce consistent line endings across Windows, macOS, and Linux
- Mark files as binary so Git won’t try to diff them
- Customize merge behavior during conflicts
- Improve diffs for specific file types
- Control what gets included in
git archive
Unlike .gitignore, which tells Git what not to track,.gitattributes tells Git how to treat files that are tracked.
That’s the whole point.
Fine-grained control over file behavior in Git —
defined once, enforced everywhere.



