Post

Git - Use gitattributes to control line endings

Use .gitattributes to control the line endings for files that are in the repository.

The above settings are useful when working with others who use other Operating Systems, because each OS has its own line endings for files.

When determining which settings to apply, Git gives higher precedence to the .gitattributes file.

  • Every text file is checked out with LF line endings in the working directory (eol=lf)
  • Every potentially introduced CRLF in a text file will be converted back to LF on staging (* text=auto)

Git documentation describes the “Formatting and Whitespace” options available when installing it. But I’m not going to check each everyone’s git installation to confirm that they’ve set these up as I’d like

After coming across these settings in a spectral’s commit, I decided to use them too and add them to my git utilities.

This post is licensed under CC BY 4.0 by the author.