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.
To enforce LF for all Git repositories on Windows, let's edit the global
autocrlf = input
eol = lf
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 🧐.