1001Ferramentas
📜 Dev

.gitattributes Generator

Generate .gitattributes to normalize line endings, mark binaries, configure diff and override GitHub linguist language stats.

The file that tells Git how to treat each kind of file

.gitattributes is less famous than .gitignore and solves a different class of problem. Where ignore says what stays out of the repository, attributes says how Git should handle what is already in: which files are text and may have their line endings normalised, which are binary and should not be diffed line by line, and which should be excluded from the language statistics.

Tick the options that fit your project and the page assembles the file. The most valuable rule is usually the first: text=auto eol=lf normalises line endings to LF inside the repository, regardless of which system the commit came from. That puts an end to the classic diff showing the whole file as modified just because someone opened it in a Windows editor.

The remaining options cover images, PDFs and audio, marked as binary so Git stops trying to build a diff or merge content; dependency and build output folders, marked vendored and generated so they do not skew GitHub's language bar; and documentation, marked as such. Save the result as .gitattributes in the repository root. For files already committed with CRLF, you have to run git add --renormalize . once for the change to take effect.

Frequently asked questions

What is the difference between text=auto and core.autocrlf?
The core.autocrlf setting applies to the machine that defined it and vanishes when someone else clones. .gitattributes travels with the repository, so the rule holds for everyone, CI included. When both exist, attributes wins.
Does marking a file as binary change it?
It does not change the content. What changes is behaviour: Git stops converting line endings, generates no textual diff, and treats conflicts as "pick one version". That is exactly what you want for PNG and PDF, which would be corrupted by line normalisation.
What is linguist-vendored for?
The language bar GitHub shows at the top of a repository is computed by linguist. If a vendor folder or a third-party library counts, a Python project can show up as 80% JavaScript. Marking those as vendored or generated removes them from the statistics without removing them from the repository.

Related Tools