All Tools View Categories About Contact Privacy

.gitattributes Generator

Line-ending policies, binary files, merge strategies, language detection and archive rules — assembled into one .gitattributes file, generated locally.

Runs entirely in your browser — your choices never leave this page.
0
groups
0
sections
0
lines
0
rules

  

About .gitattributes Generator

Every Git repository has a story about line endings: one developer works on macOS and checks in LF, a teammate on Windows checks out and edits on CRLF, and before long a pull request shows a false diff on every line of a file that only "changed" its newline bytes. The .gitattributes file is the machine-readable contract that prevents this class of problem, and it does far more besides: it tells Git which files are binary so they are never corrupted by text conversion, which files should merge by taking every version, how GitHub detects languages, and which paths to exclude when a release archive is built with git archive.

This generator assembles a professional .gitattributes file from a small number of well-understood groups. Automatic text detection writes the standard * text=auto marker so Git decides text versus binary intelligently. The binary group spells out common formats — images, archives, fonts, executables, media — with the binary attribute so none of them are ever touched by line-ending conversion. Line-ending groups then decide the checkout convention: force LF everywhere, force CRLF, or keep the native setting, with dedicated rules for shell scripts and batch files that already expect a specific style. Each group is a heading-and-lines block with a readable comment, so the exported file stays documented even when it grows.

Beyond endings, the merge and diff groups save real time in busy repositories. Files marked merge=union — package-lock.json, yarn.lock, Cargo.lock, composer.lock, poetry.lock, Gemfile.lock and CHANGELOG.md among them — resolve against each other by keeping both versions, so routine dependency bumps stop producing merge conflicts. Diff drivers for PDF, Office documents, notebooks and gettext files prepare the ground for external diff tools when they are configured in .git/config. The linguist group keeps GitHub statistics honest: you can pin a language to a file type, mark vendored third-party code so it is excluded from language counts, and hide generated files and documentation from the popular-language view.

The export-ignore group finishes the file for distribution: paths such as .github, docs, tests, .gitignore and the attributes file itself are stripped from git archive output, so release tarballs ship only real source. A custom-lines box appends your own rules under a dedicated section, and duplicate removal keeps the result compact when groups share entries. Statistics report how many groups are active, how many lines the file spans and how many actual attribute rules it holds — non-comment, non-blank lines only — so you always know what the file does before you commit it.

Everything happens in the browser: attribute lists are bundled with the page, generation is pure JavaScript, and no network request is made. Click Load sample to see a typical mixed repository configuration, or clear everything and build your own stack group by group. When the preview looks right, copy it to the clipboard or download it as .gitattributes, place it in the repository root, and commit it — from then on every contributor and every archive shares the same rules, and the silent line-ending emergencies of the past stay resolved.

Features

  • Automatic text detection — the standard * text=auto baseline, on by default in the sample.
  • Binary whitelist — images, archives, fonts, executables and media marked binary so they are never mangled.
  • Line-ending policies — force LF, force CRLF, or native, with separate rules for scripts and batch files.
  • merge=union presets — lock files and CHANGELOG merge by keeping both sides, killing routine conflicts.
  • Diff driver hints — PDF, Office documents, notebooks and gettext entries ready for external tools.
  • Linguist controls — pin languages, mark vendored and generated files, hide documentation.
  • export-ignore — strip .github, docs, tests and ignore files from git archive output.
  • Custom lines carried under their own section, plus automatic duplicate removal.
  • Live statistics — groups, lines and real attribute rules update on every change.
  • Sample, Check all shown, Clear, Copy and Download controls, fully client-side.

How to Use

  1. Start from the sample. Load sample pre-selects a balanced repository configuration you can prune to fit your own stack.
  2. Choose the baseline. Keep Automatic text detection on, and decide whether the binary whitelist fits your file types.
  3. Pick a line-ending policy — LF for cross-platform, CRLF for Windows checkouts, or the native option, adjusting script rules as needed.
  4. Enable merge union for the lock files your project actually uses, and add diff drivers for documents you diff.
  5. Configure linguist if you care about GitHub language statistics, and export-ignore if you ship git archive releases.
  6. Add custom lines such as per-file attributes that no group covers, then generate and review the stats.
  7. Copy or download the result as .gitattributes, save it in the repository root, and commit it.

Examples

Example 1 — Cross-platform Node.js team. Automatic detection plus binary whitelist plus LF plus merge=union on package-lock.json and yarn.lock. Every push stays clean regardless of contributor OS.

Example 2 — Windows .NET checkout. CRLF policy with CRLF rules for .bat and .cmd, text-auto baseline, and binary entries for executables and archives.

Example 3 — Python package with releases. LF line endings, binary whitelist, linguist pinning .py as Python, and export-ignore removing tests and docs from PyPI source archives.

Example 4 — Documentation-heavy repo. merge=union on CHANGELOG.md and VERSION plus the linguist documentation flags so prose stops skewing language stats.

Example 5 — Design assets in a web repo. Binary entries for svg/woff/png alongside the vendor linguist flags; SVGs in subfolders are kept out of language counts while sources stay binary-safe.

Benefits

  • Ends false line-ending diffs — the repository defines one convention that overrides every contributor's local setting.
  • Protects binary files — images, fonts, executables and archives are never corrupted by text conversion.
  • Fewer merge conflicts — lock files and changelogs merge by taking every version with merge=union.
  • Honest language stats — linguist pins and vendored flags keep GitHub counts accurate.
  • Clean release archives — export-ignore keeps build tooling and docs out of git archive tarballs.
  • Documented output — every group ships with a comment header, so reviewers understand each rule.
  • Fully local — generation happens in your browser, nothing is uploaded, and offline use is supported.

Frequently Asked Questions

What is a .gitattributes file for?
It sets per-repository file attributes that Git honours: which files are text and how line endings are normalized, which files are binary, how certain files merge, how the repository is packaged by git archive, and how GitHub detects languages.
How do I generate one?
Tick the attribute groups that match your project, add custom lines if needed, and press Generate. The merged file is produced instantly with a header above each group, then copy it or download it as .gitattributes and place it in the repository root.
Do I need to configure line endings too?
A .gitattributes with text=auto and eol directives is the modern, portable way and overrides core.autocrlf settings. Patterns like "eol=lf" (Linux/macOS) or "eol=crlf" (Windows checkouts) decide how Git stores and checks out files.
How do binaries get detected?
"* text=auto" makes Git guess text versus binary, and the binary group adds explicit entries for common formats (images, archives, fonts, executables) so Git never mangles them. Each can be turned on independently.
What does merge union do?
Files marked "merge=union" merge by keeping all versions from both sides instead of conflicting — handy for lock files and CHANGELOG.md where a simple join beats a manual merge every time.
What is linguist used for?
GitHub's Linguist recognises languages from file extensions. Its attributes let you pin a language to a file type, mark vendored or documentation files so they are excluded from language statistics, and hide generated files.
What does export-ignore do?
Files and folders marked export-ignore are left out of git archive tarballs — useful when you distribute releases and do not want .github, docs, tests or ignore files shipped inside them.
Does the generated file work in git archive?
The export-ignore group produces standard gitattributes syntax evaluated by git archive at packaging time, so the excluded paths disappear from archives on any machine that creates them, without touching your working tree.
Is my data uploaded anywhere?
No. Attribute lists are bundled with the page, generation is pure JavaScript, and nothing leaves the browser. The tool also works offline.
Where should I put the file?
Save it as .gitattributes in the repository root, next to .git. Because attributes can override user and global configuration, committing it keeps line endings and merge behaviour identical for every contributor.