From the docs :
Each line in the .gitattributes file (or .git/info/attributes ) has the form:
pattern attr1 attr2 ...
So, the template is * , which means all files, and the attribute is text=auto .
What does text=auto do? From the documentation:
When the text is set to "auto", the path is specified to automatically normalize the final line. If Git decides that the content is text, its line ending is normalized to LF upon registration.
What is the default behavior if it is not enabled?
Not chosen
If no text attribute is specified, Git uses the core.autocrlf configuration variable to determine if the file should be converted.
What does core.autocrlf do? From the docs:
core.autocrlf
Setting this variable to โtrueโ is almost the same as setting the text attribute to โautoโ for all files, except that text files are not guaranteed normalized: files containing CRLF in the repository will not be affected. Use this option if you want CRLF lines to end in your workspace although the repository does not have normalized line endings. This variable can be set to input, and in this case, the output conversion is not performed.
If you think all this is as clear as dirt, you are not alone.
Here, what * text=auto does in my words: when someone commits a file, Git guesses whether this file is a text file or not, and if so, it will commit a version of the file where all CR + LF bytes are replaced by bytes Lf. This does not affect what files look in the working tree, there are other settings that will convert LF bytes to CR + LF bytes when checking a file.
Recommendation:
I would not recommend putting * text=auto in a .gitattributes file. Instead, I would recommend something like this:
*.txt text *.html text *.css text *.js text
This explicitly indicates which files are text files that convert CRLF in LF to an object database (but not necessarily in the working tree). We had a repo with * text=auto , and Git guessed that it was a text file for the image file, which caused it to be damaged, because it replaced L + LF bytes with LF bytes in the object database. It was not fun to debug.
If you must use * text=auto , put it as the first line in .gitattributes so that later lines can override it. This seems to be an increasingly popular practice.