Skip to content

Git Attributes

In one line

The .gitattributes file assigns attributes to paths, controlling line endings, diff, merge, and export behavior per file.

In simple words

The .gitattributes file lets you assign attributes to specific paths or patterns in your repo, controlling how Git treats them. It is the per-repo companion to global git config, and is committed to the repo so all contributors share the same rules.

Common uses: enforcing line endings (* text=auto or *.bat text eol=crlf), marking binary files to skip diff (*.png binary), custom diff/merge drivers for generated files, and export-ignore to exclude files from archives. It solves cross-platform line-ending issues that .gitconfig alone cannot.

Without .gitattributes, line-ending behavior depends on each developer's global config, leading to noisy diffs and broken files. With it, the repo declares the correct behavior and Git enforces it consistently for everyone.

Example

bash
# .gitattributes file contents:
# Auto-detect text vs binary, normalize line endings in repo
* text=auto

# Force CRLF for Windows batch files
*.bat   text eol=crlf
*.cmd   text eol=crll

# Force LF for shell scripts
*.sh    text eol=lf

# Mark binaries — no diff, no text conversion
*.png   binary
*.zip   binary

# Custom merge for generated lockfile
package-lock.json merge=ours

* text=auto normalizes line endings. eol=crlf/lf forces a specific ending. binary skips diff and conversion. merge=ours keeps our version on conflict.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary