Skip to content
Latchkey

Git "LF will be replaced by CRLF" warning breaks CI on Windows

Git on Windows is rewriting line endings on checkout because core.autocrlf is enabled. The warning is harmless, but the resulting CRLF churn breaks dirty-tree checks, formatting gates, and shell scripts.

What this error means

You see the LF/CRLF warning during checkout, and then a later step fails: git diff reports the whole tree changed, a "no uncommitted changes" check fails, or a shell script errors on carriage returns. Deterministic for a given autocrlf setting.

cmd
warning: in the working copy of 'scripts/build.sh', LF will be replaced by CRLF
the next time Git touches it
# downstream:
error: Your local changes to the following files would be overwritten
The working tree is dirty after checkout (CRLF rewrite)

Diagnose it: which runtime is actually on PATH?

Runners ship multiple versions of most runtimes and select one through a version manager. When a setup action and a version file disagree, the resulting error is about your code rather than the version.

Terminal
which -a <runtime>
<runtime> --version
echo "PATH=$PATH" | tr ":" "\n" | head -20

# does a version file in the repo disagree with the workflow?
cat .tool-versions .nvmrc .ruby-version .python-version 2>/dev/null

Common causes

core.autocrlf is true on the Windows runner

Windows git images default to converting LF to CRLF on checkout. Files committed with LF are rewritten locally, so the working tree differs from HEAD.

No .gitattributes pins line endings

Without a .gitattributes declaring eol, each platform applies its own conversion, so the same repo looks dirty on Windows but clean on Linux.

How to fix it

Disable autocrlf for the checkout

Turn off the conversion before checking out so files keep their committed endings.

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

Pin line endings with .gitattributes

Declare endings per file type so every platform agrees and the tree never looks dirty.

cmd
* text=auto eol=lf
*.bat text eol=crlf
*.ps1 text eol=crlf

How to prevent it

  • Commit a .gitattributes that pins eol per file type, and set core.autocrlf=false on Windows runners so checkout does not rewrite endings.

Frequently asked questions

What causes Git "LF will be replaced by CRLF" warning breaks CI on Windows?
There are 2 common causes: core.autocrlf is true on the windows runner and no .gitattributes pins line endings. Windows git images default to converting LF to CRLF on checkout.
How do I fix Git "LF will be replaced by CRLF" warning breaks CI on Windows?
There are 2 fixes depending on which cause you have: disable autocrlf for the checkout and pin line endings with .gitattributes. Work through them in order, since the first is the most common.
What does Git "LF will be replaced by CRLF" warning breaks CI on Windows actually mean?
You see the LF/CRLF warning during checkout, and then a later step fails: git diff reports the whole tree changed, a "no uncommitted changes" check fails, or a shell script errors on carriage returns.
How do I stop Git "LF will be replaced by CRLF" warning breaks CI on Windows happening again?
Commit a .gitattributes that pins eol per file type, and set core.autocrlf=false on Windows runners so checkout does not rewrite endings.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card