No Login Data Private Local Save

.gitattributes Generator - Online Line Ending & Diff Rules

10
0
0
0

.gitattributes Generator

Configure Git line endings, diff rules, merge strategies, and linguist overrides with ease.

Build your .gitattributes file, preview, copy, or download instantly.

Presets:
Rule Configuration 0 rules
Supports glob patterns & brace expansion
Click tag buttons below to build attributes
Type:
text binary text=auto -text
EOL:
eol=lf eol=crlf
Diff & Merge:
diff -diff merge -merge
Export:
export-ignore
Linguist:
linguist-vendored linguist-generated linguist-documentation linguist-language= linguist-detectable=false
Current Rules
Pattern Attributes Actions
No rules yet. Add a rule or load a preset.
.gitattributes Preview

Your .gitattributes content will appear here

Add rules or load a preset to get started

Frequently Asked Questions

Everything you need to know about .gitattributes, line endings, and Git attributes

What is a .gitattributes file?
A .gitattributes file is a Git configuration file placed in your repository root (or any subdirectory) that assigns attributes to file paths. These attributes control how Git handles line endings, diff output, merge strategies, export rules, and even how GitHub classifies languages via linguist attributes. It ensures consistent behavior across all contributors regardless of their operating system.
What's the difference between CRLF and LF?
CRLF (\r\n) is the traditional Windows line ending — two characters: Carriage Return + Line Feed. LF (\n) is the Unix/Linux/Mac line ending — a single Line Feed character. When developers on different OSes work on the same files without proper Git configuration, you may see entire files marked as changed due to line ending differences. Setting * text=auto in .gitattributes tells Git to automatically normalize line endings to LF in the repository while checking out CRLF on Windows working trees.
What does * text=auto do?
* text=auto is the recommended best practice for most projects. It tells Git to automatically detect whether each file is text or binary. For text files, Git normalizes line endings to LF on commit, and checks out with the platform-appropriate ending (CRLF on Windows, LF on Unix). For binary files (images, archives, etc.), Git leaves them untouched. This single line prevents most cross-platform line ending issues.
How do I handle binary files in .gitattributes?
Mark binary files with the binary attribute to tell Git they should not be diffed, merged, or have their line endings modified. For example: *.png binary, *.jpg binary, *.zip binary. You can also use -diff -merge -text as a more explicit equivalent. For Unity projects, files like .unity, .prefab, .asset, and .mat should be marked as binary.
Should I commit .gitattributes to my repository?
Absolutely yes! The .gitattributes file should be committed to your repository so that every contributor uses the same settings. Git applies attributes from .gitattributes files found in the repository. If each developer had their own local configuration, you'd still face inconsistent line endings and diff behavior. Committing it ensures team-wide consistency and is a hallmark of a well-configured project.
What are linguist attributes and why use them?
Linguist is GitHub's language detection library. Linguist attributes in .gitattributes let you override its behavior: linguist-vendored marks third-party/vendor code (excluded from stats), linguist-generated marks auto-generated files, linguist-documentation marks documentation files, and linguist-language=Python forces a specific language classification. These are incredibly useful for cleaning up your repository's language statistics on GitHub.
What is export-ignore?
The export-ignore attribute tells git archive to exclude matching files from generated archives (tarballs, zip files). This is handy for excluding development-only files like .github/ workflows, tests/, .editorconfig, or CI configs from release packages. Example: .github/* export-ignore or tests/* export-ignore. It keeps your release artifacts clean and professional.
How to configure Unity projects properly?
Unity projects require special care: scene files (.unity), prefabs (.prefab), assets (.asset, .mat) are binary and should be marked binary. Meta files (.meta) should be text eol=lf. C# scripts (.cs) and shaders should use text eol=lf. Our Unity preset handles all of these automatically — just load it and you're set.
.gitattributes vs .gitignore — what's the difference?
.gitignore tells Git which files to completely ignore — they won't be tracked at all. .gitattributes tells Git how to handle tracked files — line endings, diff behavior, merge strategies, etc. They serve different purposes but work together. A well-configured project typically has both: .gitignore for build artifacts and IDE files, .gitattributes for consistent file handling across platforms.
Can I have multiple .gitattributes files?
Yes! You can place .gitattributes files in subdirectories. Git applies attributes from the file closest to the matched path. A root .gitattributes provides project-wide defaults, while subdirectory .gitattributes files can override or extend rules for specific folders. Patterns in subdirectory files are relative to that directory. This is useful for monorepos or projects with distinct subsystems.
Git Attributes Quick Reference
Line Ending Attributes
  • text — normalize line endings
  • text=auto — auto-detect & normalize
  • binary — no line ending conversion
  • -text — skip conversion entirely
  • eol=lf — force LF on checkout
  • eol=crlf — force CRLF on checkout
Diff & Merge Attributes
  • diff — treat as diffable text
  • -diff — skip in diffs
  • diff=NAME — use named diff driver
  • merge — allow 3-way merge
  • -merge — prevent merge attempts
  • merge=NAME — use named merge driver
GitHub Linguist Attributes
  • linguist-vendored — exclude from stats
  • linguist-generated — mark as generated
  • linguist-documentation — mark as docs
  • linguist-language=NAME — override language
  • linguist-detectable=false — hide from stats
  • export-ignore — exclude from archives