.gitattributes Generator

Generate .gitattributes files for line ending normalization, binary file handling, and custom diff/merge settings.

About This Tool

The .gitattributes Generator is a free browser-based tool that helps you create comprehensive .gitattributes files for your Git repositories. A .gitattributes file controls how Git handles files in your project — from line ending normalization to diff algorithm selection and merge strategies. Getting these settings right is critical for teams working across different operating systems (Windows, macOS, Linux) where line ending conventions differ.

The tool provides pre-built templates for popular languages and frameworks including Web (HTML/CSS/JS), Python, Java, Go, Rust, C/C++, C#/.NET, Unity, Ruby, PHP, and DevOps configurations. Each template includes the correct text, binary, and diff=language attributes for common file extensions in that ecosystem. You can combine multiple templates and add custom rules with fine-grained control over text normalization (text=auto, eol=lf, eol=crlf), diff settings (diff, -diff, diff=python), merge strategies (merge, -merge), and GitHub Linguist attributes (linguist-vendored, linguist-generated, linguist-language).

The global * text=auto header is included by default, which tells Git to detect text files automatically and normalize their line endings to LF in the repository. This is the recommended starting point for any project. From there you can add language-specific diff drivers so that git diff produces more meaningful function-level hunks, mark binary files to prevent corruption, and set merge strategies for files that need special handling.

If you are managing a .gitignore file alongside your attributes, check out the .gitignore Generator. For building Git commands visually, try the Git Command Builder. And for comparing file differences, the Diff Viewer provides a side-by-side view with character-level highlighting.

All processing happens entirely in your browser. Your file patterns and configuration never leave your machine — there are no server round-trips, no logging, and no third-party services involved.

How to Use

  1. Toggle the * text=auto button to include the recommended global line ending normalization header.
  2. Click one or more language/framework template buttons to add pre-configured rules for your project's tech stack.
  3. Click Add Rule to create custom entries with a file pattern (e.g., *.csv, vendor/**).
  4. For each custom rule, select the line ending attribute (text, text eol=lf, binary, etc.) from the dropdown.
  5. Optionally set a diff driver (e.g., diff=python), merge strategy (merge or -merge), or Linguist attribute.
  6. Review the generated .gitattributes content in the preview panel on the right.
  7. Click Copy or press Ctrl+Shift+C to copy to clipboard, or click Download to save as a .gitattributes file.

Popular .gitattributes Examples

View all .gitattributes examples →

FAQ

What does * text=auto do?

The line `* text=auto` tells Git to automatically detect whether a file is text or binary. For text files, Git normalizes line endings to LF when storing them in the repository and converts them to the platform's native line ending (CRLF on Windows, LF on macOS/Linux) on checkout. This prevents mixed line ending issues in cross-platform teams.

What is the difference between text and binary attributes?

The `text` attribute tells Git the file is a text file that should undergo line ending normalization. The `binary` attribute is a shorthand for `-text -diff -merge`, which means Git will not normalize line endings, will not attempt to produce textual diffs, and will not attempt three-way merges. Use `binary` for images, compiled files, fonts, and other non-text assets.

How do diff=language drivers work?

Setting `diff=python` (or another language) tells Git to use a language-aware diff driver that produces better hunk headers. Instead of showing arbitrary context lines, Git will display the function or class name that contains the change. Git has built-in support for languages including python, java, ruby, php, cpp, csharp, golang, rust, html, css, and markdown.

What are linguist attributes used for?

GitHub's Linguist library uses `.gitattributes` to determine repository language statistics. `linguist-vendored` marks files as third-party code (excluded from stats), `linguist-generated` marks auto-generated files, and `linguist-language=X` overrides the detected language for a file pattern. These attributes only affect GitHub's language bar and statistics.

Should I use eol=lf or eol=crlf?

Use `eol=lf` for files that must always have Unix-style line endings regardless of the developer's OS, such as shell scripts (.sh) and Makefiles. Use `eol=crlf` for files that require Windows-style line endings, such as .sln (Visual Studio solution) files and batch scripts (.bat, .cmd). For most other files, `text=auto` with no explicit eol setting is sufficient.

Is my data safe?

Yes. All processing runs entirely in your browser using JavaScript. No data is sent to any server. Your file patterns and configuration never leave your machine. You can verify this by checking the Network tab in your browser's developer tools while using the tool.

How do merge attributes work?

The `merge` attribute enables three-way merge for a file (the default for text files). The `-merge` attribute disables merging, so Git will always report a conflict when both sides modify the file. You can also specify custom merge drivers like `merge=unityyamlmerge` for Unity scene files, which uses a specialized merge tool that understands the YAML structure of Unity assets.

Related Tools