Darek Kay's picture
Darek Kay
Solving web mysteries

Using LF line endings on Windows

Historically, Windows uses different line endings (CRLF) than Linux/macOS (LF). This often leads to issues on cross-platform development teams, e.g.:

  • Inconsistent (mixed) line endings
  • Large Git diff logs
  • Issues with published CLI modules

One common solution is to set Git's autocrlf option to true, which will ensure LF line endings in the repository and system-dependent line endings in the working directory.

Since Prettier 2.0, a formatter for JavaScript, enforced LF line endings by default on all operating systems, I reconsidered my settings. So far, I haven't found any reason not to use LF endings on Windows.

To enforce LF for all Git repositories on Windows, let's edit the global ~/.gitconfig:

  autocrlf = input
  eol = lf

Using input will convert CRLF to LF on commit but not the other way around.

This approach works fine on my computer, but my team colleagues might use a different configuration. If you'd like to enforce those settings on repository level, create a <repo>/.gitattributes file with the following content:

* text=auto eol=lf

Finally, apply those new settings in the working directory:

git add --renormalize .

That's it — no more headaches 🧐.

Related posts

Using LF line endings on Windows