Workspace

Fixing CRLF Issues in Git: Enforcing LF for Your Project

The error Expected linebreaks to be 'LF' but found 'CRLF' is a common headache for developers — especially those working on Windows — when dealing with Git and ESLint. This guide explains how to configure Git to use the standard LF line endings, helping you avoid unnecessary errors, keep your codebase clean and consistent, and make collaboration smoother.

Why Does This Error Happen?

If you’ve worked on projects configured with ESLint, you’ve probably encountered this error:

Expected linebreaks to be 'LF' but found 'CRLF'

The first time you see it, it can feel unnecessarily frustrating. Why do such small details cause so much confusion when coding on Windows?

Quick Fix

Simply run these two commands in your command line tool of choice (PowerShell, CMD, Git Bash, Terminal, etc.):

git config --global core.autocrlf false
git config --global core.eol lf

Done! From now on, files you create or commit will use LF (Unix-style) line endings, preventing ESLint complaints.

A Bit More Explanation

  • core.autocrlf: Controls automatic line ending conversion. Setting it to false disables Git from converting between CRLF ↔ LF.
  • core.eol: Defines the default line ending Git should use when creating new files or normalizing on commit. Setting it to lf enforces the Linux/macOS standard (LF).
  • --global: Applies the configuration to your entire system. If you only want this setting for a single repository, omit --global or use a .gitattributes file.

Per-Project Configuration

If you prefer project-specific settings, create or edit the .gitattributes file in your repository’s root directory and add:

* text eol=lf

This ensures all files in the project follow the LF standard upon commit, regardless of your operating system.

Conclusion

Configuring line endings properly from the start helps you avoid annoying errors when collaborating, especially on projects that enforce strict formatting with ESLint, Prettier, or CI/CD pipelines.