Open-source project
gitattributes/gitattributes avatar
gitattributes/gitattributes

gitattributes/gitattributes: A Template Collection for .gitattributes Rules

A collection of useful .gitattributes templates

3,894 stars591 forksGit AttributesMIT

At a glance

What is it?
The gitattributes/gitattributes repository collects per-language .gitattributes templates plus a Common file and a check.sh script. It is for people who know they need line-ending or Linguist rules and would rather copy a tested file than write one from scratch.
Who is it for?
Adopt gitattributes/gitattributes if you want a starting file for a language it already covers, or if you want check.sh to tell you which tracked files have no explicit rule. Do not adopt it if you expect a tool: nothing here runs on your repository by itself, and the README documents no rollback for a renormalization you have already pushed.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 125 days ago.
What is it written in?
Mainly Git Attributes, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • gitattributes/gitattributes3,894 ★ · +30
Star history
Repository2026-09-242026-11-24
gitattributes/gitattributes3.9k3.9k

30 Stars in the last 61 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What the templates solve, and who ends up needing them

A .gitattributes file answers questions Git asks about every path: should this file be normalized to LF on commit, is it binary, should GitHub count it toward the language bar. Most repositories never write one, and that is fine until it is not. The failure usually shows up as a diff full of line-ending changes, a generated bundle counted as source code, or a Unity project whose asset files are treated as text.

The gitattributes/gitattributes repository is a set of templates for exactly those situations. The README describes the goal plainly: "Similarly to the .gitignore Templates, we're trying to build templates for .gitattributes." The top-level layout confirms the shape of the collection: ActionScript.gitattributes, Ada.gitattributes, C++.gitattributes, CSharp.gitattributes, Common.gitattributes, Delphi.gitattributes, Drupal.gitattributes, DyalogAPL.gitattributes, Elixir.gitattributes, Fortran.gitattributes, Go.gitattributes, Java.gitattributes, Lua.gitattributes, Markdown.gitattributes, Mathematica.gitattributes, Matlab.gitattributes, MicrosoftShell.gitattributes, ObjectiveC.gitattributes, PHP.gitattributes, Pascal.gitattributes, Perl.gitattributes, PowerShell.gitattributes, Python.gitattributes, R.gitattributes, Rails.gitattributes, Rust.gitattributes, Servoy.gitattributes, Swift.gitattributes, TinaCMS.gitattributes, Unity.gitattributes, Vim.gitattributes and Web.gitattributes, alongside a Global/ directory and a community/ directory.

That is a language and framework index, not a general-purpose tool. If your project is a polyglot monorepo, the intended workflow is to take Common.gitattributes plus one file per language and concatenate them.

How a template becomes rules in your repository

The mechanism is entirely Git's. A .gitattributes file holds one pattern per line followed by attributes, and Git consults it for normalization, diff behavior and export. This repository does not add a runtime, a hook, or a daemon. It ships text files whose contents you copy.

The README points at two references for the grammar: gitattributes(5) and the GitHub Linguist overrides documentation, which covers the Linguist-specific attributes. That split matters. Attributes such as text and eol are handled by Git itself, while linguist-generated and similar keys are read by GitHub's language detection. A template file may contain both kinds, and the repository does not separate them, so a reader who only reads the Git manual will not understand every line.

There is also a generator linked from the README, hosted at richienb.github.io/gitattributes-generator, which the README says builds gitattributes files "on the fly based on files inside of this repository." That is the closest thing to automation in the project.

Installing by copying: a first real use

There is no package to install. The repository is consumed by copying files out of it. Clone it, then copy the template that matches your stack into your project root as .gitattributes.

bash
git clone https://github.com/gitattributes/gitattributes.git
cp gitattributes/Common.gitattributes .gitattributes

The copy gives you the general exclusions the README describes as applicable to any project. If you work in more than one language, repeat it for each template you need and append the contents to the same .gitattributes file, because Git reads only the file with that name in a directory.

Once the file exists, the README's CI step reports which tracked files have no explicit rule:

sh
missing_attributes=$(git ls-files | git check-attr -a --stdin | grep 'text: auto' || printf '\n')

if [ -n "$missing_attributes" ]; then
  printf '%s\n%s\n' '.gitattributes rule missing for the following files:' "$missing_attributes"
else
  printf '%s\n' 'All files have a corresponding rule in .gitattributes'
fi

That pipeline lists every tracked file whose text attribute is still the default auto value, which is the script's definition of a missing rule. The README says a checked-in ./check.sh exists with more features, and that ./check.sh --help lists the options it adds on top of this pipeline. The README does not enumerate them, so read the help output rather than guessing.

The check.sh gap: what the script does not cover

The README's own CI snippet defines a missing rule as a file where git check-attr reports text: auto. That is a narrow definition, and it is worth being explicit about what falls outside it. A file can have a rule that sets text=auto explicitly and still pass, a file can be marked binary and never appear in the list, and a file with only a linguist-generated attribute will still show as text: auto and be flagged as missing. The script is a coverage check for text handling, not a validator of your whole attribute set.

The second limitation is that nothing in the repository enforces the rules at commit time. There is a .pre-commit-config.yaml at the top level, but the README does not describe what it does, so treat it as an internal detail of this repository rather than a feature you inherit. If you copy a template and never wire the check into your own CI, drift is silent.

The third is renormalization. The related search terms around gitattributes renormalize point at a real hazard: changing text or eol rules on files that are already committed does not rewrite history, and the README does not document a rollback procedure for a renormalization commit that has been pushed. That is a gap a reader should notice before touching a shared branch.

Where this collection beats writing rules from memory

The alternative most teams reach for is a hand-written .gitattributes, usually three lines long and usually wrong for a language with mixed content. A second alternative is a generator that inspects a repository and emits rules, which is what the linked richienb.github.io tool does; the difference is that the generator derives rules from the files present, while this repository gives you a curated file per language that you review before adopting. Curated files are more predictable and easier to diff in review, but they cannot know that your repository has a vendored directory that should be excluded.

A third alternative is doing nothing and relying on core.autocrlf, which is a per-clone setting. The difference in approach is fundamental: autocrlf is a local preference that every contributor must set correctly, while .gitattributes is committed and travels with the repository. That is the actual case for adopting a template here rather than asking each developer to configure their machine.

The repository's contribution rule reinforces how the files are meant to be read: the README asks contributors to modify only one file per commit, so that merging stays manageable. The templates are meant to be small, single-purpose and reviewable, not a monolithic generated blob.

Maintenance, licensing and the cost of copying templates

The repository is not archived, and the last push was on 2026-07-22. That is recent enough that the collection is still being touched, but the README does not describe a release process, and the repository has no published releases, so there is no version to pin. You consume it by copying files, which means you own the copy. When a template changes upstream, nothing tells you. The practical upgrade path is to diff your .gitattributes against the current template for each language you use, which is a manual step the README does not document.

The licence is MIT, stated in the LICENSE file at the top level. For a set of text templates that is permissive in the ordinary sense: you can copy the files into your repository, including a commercial one, provided you keep the licence terms. This is not legal advice, and if your organization has rules about attributing copied configuration files, check them before pasting a template into a proprietary repository.

Editorial conclusion

Adopt gitattributes/gitattributes if you want a starting file for a language it already covers, or if you want check.sh to tell you which tracked files have no explicit rule. Do not adopt it if you expect a tool: nothing here runs on your repository by itself, and the README documents no rollback for a renormalization you have already pushed. Before copying anything, read Common.gitattributes and the template for each language in your tree, then run ./check.sh --help to see which options the checked-in script actually accepts in your checkout.

Frequently asked questions

What is the purpose of gitattributes?

A .gitattributes file tells Git how to treat paths in a repository, for example whether a file is text and should be normalized, or binary. The gitattributes/gitattributes repository collects templates for those rules per language, and the README points to gitattributes(5) for the full grammar.

Should I commit the .gitattributes file?

The whole design of the template collection assumes yes. The files are meant to be copied into your repository root as .gitattributes so the rules travel with the repository rather than living in each developer's local Git configuration.

Is .gitattributes necessary?

The README frames the templates as general exclusions that may apply to any project, and says to consider including them if they are applicable. Nothing in the repository forces a .gitattributes file into a project that does not need one.

How to make a gitattributes file?

Clone the repository, copy Common.gitattributes to your project root as .gitattributes, then append the template for each language you use to the same file. The README also links a generator at richienb.github.io/gitattributes-generator that builds a file from the templates in the repository.

how to use .gitattributes

Copy the relevant template into your repository as .gitattributes, then check coverage with the README's CI snippet or the checked-in ./check.sh, which reports files that still have no explicit rule. Run ./check.sh --help for the available options.

Official sources

  1. gitattributes/gitattributes on GitHub
  2. Issues
  3. License: MIT
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/gitattributes-gitattributes.svg)](https://hysenlabs.com/projects/gitattributes-gitattributes)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/gitattributes-gitattributes.svg)](https://hysenlabs.com/projects/gitattributes-gitattributes)

Was this useful?