Sitemap
Qasim-AJ

Qasim-AJ

SWE | Building products with Typescript and Python. Can catch up with me on LinkedIn and YouTube: @Qasim-AJ

1 min readJan 1, 2026

--

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=lf

Example project structure

project/
├── .gitattributes
├── entry-point.sh
├── README.txt
├── package.lock
└── src/
└── main.js

How this applies

  • README.txt will always use LF line endings — even on Windows
  • entry-point.sh won’t break due to CRLF issues in Docker or CI
  • package.lock won’t generate noisy or meaningless diffs

Common uses of .gitattributes

  1. Enforce consistent line endings across Windows, macOS, and Linux
  2. Mark files as binary so Git won’t try to diff them
  3. Customize merge behavior during conflicts
  4. Improve diffs for specific file types
  5. 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.

--

--

Qasim-AJ
Qasim-AJ

Written by Qasim-AJ

SWE | Building products with Typescript and Python. Can catch up with me on LinkedIn and YouTube: @Qasim-AJ