r/git • • Oct 30 '26

What is .gitattributes

What is .gitattributes? I'm just a beginner of git, and i just found godot-generated .gitattribute, I also have some of it and it's kinda like literally attributes?

0 Upvotes

11 comments sorted by

10

u/elperroborrachotoo Oct 30 '26

It customizes handling for special files or file types.

The most common use case is telling git what files are binary and what files are text. (Only the latter are affected by platform-specific end-of-line-translation, if tis option is active.)

It's also used by git-lfs ("Large File System", a git add-on to handle large binary files better).

In general, you specify a pattern (or regexp) and various options:

*.psd filter=lfs diff=lfs merge=lfs -text

This allwos to use custom diff tools or merge policies for some files.

5

u/WoodyTheWorker Oct 30 '26

git help attributes

3

u/CartographerDue5382 Oct 30 '26

for the godot one, the line that actually matters is usually * text=auto eol=lf. that stops windows from checking scripts out as crlf and making the whole file look changed. it's just per-path rules, so you can also put *.png binary or *.import linguist-generated if github's language bar gets eaten by import files. if your diffs already look normal you can leave it alone.

1

u/lajawi Oct 30 '26

Linguist generated could be useful! From your explanation I take GitHub and alike will not count those files toward the languages used?

2

u/CartographerDue5382 Oct 30 '26

yea. linguist-generated just tells github's linguist to skip those files for the language bar. doesn't change the repo, diffs, or what actually gets committed. same idea as linguist-vendored if some folder is eating the stats.

5

u/_AACO Oct 30 '26

Have you read the official docs or the "easy to read" version of w3 schools?

1

u/JesseNL Oct 30 '26

Is this the new stack overflow? A question can lead to discussion, I clicked on this thread to see what people are using it for in their specific jobs.

2

u/_AACO Oct 30 '26

Is this the new stack overflow?

Just because I asked if OP read the 2 best places to get his answer from?

A question can lead to discussion

There is nothing to discuss when the question is "what is <something very well documented>?"

If OP, for example asked "why use .gitattributes instead of shell scripts to do <thing>?" that could lead to a discussion.

If OP asked for help setting up .gitattributes I would've helped.

what people are using it for in their specific jobs.

OP does not ask that in the title or the text post though. But since you're interested in that I can share what I use it for. Standardizing line endings, enabling LFS and modify diff behaviour.

1

u/JesseNL Oct 30 '26

All correct. Maybe came I off too heavy. I just think that a plain question like this should lead to discussion, and you're comment isn't encouraging that (neither are mine for that matter)

1

u/waterkip detached HEAD Oct 31 '26

Rtfm is a valid answer