"LF will be replaced by CRLF" is a warning, not an error: Git is telling you a file has Unix-style (LF) line endings and that, because core.autocrlf is true, it will write Windows-style (CRLF) endings into your working folder the next time it checks the file out. To stop it for a project, commit a .gitattributes file with * text=auto; to silence it only for yourself, change core.autocrlf.
The exact text in current Git (2.45 on Windows, run as a test for this article) is:
warning: in the working copy of 'app.js', LF will be replaced by CRLF the next time Git touches it
Git releases from before the message was reworded in 2022 print warning: LF will be replaced by CRLF in app.js. followed by The file will have its original line endings in your working directory. Same meaning.
What LF and CRLF are
Text files mark the end of each line with invisible characters. Linux and macOS use one character, line feed (LF, \n). Windows traditionally uses two, carriage return plus line feed (CRLF, \r\n). Most editors handle both, but some tools don't: a shell script with CRLF endings fails on Linux, and a diff can show every line as changed when only the endings differ.
Git can convert between the two so that the repository stores LF and each developer's working folder has whatever their platform prefers. The warning appears when that conversion is switched on and a file doesn't match.
Why the warning appears
The core.autocrlf setting controls the conversion. The Git manual says that setting it to true "is the same as setting the text attribute to "auto" on all files and core.eol to "crlf"": text files are stored with LF and written to your working folder with CRLF. You added a file that has LF endings, so Git warns that it will turn them into CRLF on the next checkout.
Many people never set this themselves: on Git for Windows it is often already set in Git's system-wide config file, which the installer writes. Check where yours comes from:
git config --show-origin --get-all core.autocrlf
Example output on a default Git for Windows install:
file:C:/Program Files/Git/etc/gitconfig true
The mirror-image warning, CRLF will be replaced by LF, appears when core.autocrlf is input and you add a file with CRLF endings. input converts to LF when committing and does no conversion on checkout.
The three core.autocrlf settings
| Value | On commit | On checkout | Typical use |
|---|---|---|---|
true | CRLF to LF | LF to CRLF | Windows (GitHub's recommendation) |
input | CRLF to LF | No conversion | macOS and Linux (GitHub's recommendation) |
false | No conversion | No conversion | Files are stored exactly as written |
Set it for your user account with, for example, git config --global core.autocrlf input. The problem with relying on this setting is that it is personal: every contributor has their own value, so the same repository can end up with a mix of endings.
Fix it for the whole project: .gitattributes
A .gitattributes file in the repository root sets line-ending rules that travel with the code. When a file's text or eol attribute is set there, Git uses it instead of falling back to core.autocrlf. A sensible starting point:
# Let Git detect text files and store them with LF
* text=auto
# Files that must keep LF everywhere (they break with CRLF)
*.sh text eol=lf
# Files that must be CRLF on checkout
*.bat text eol=crlf
*.cmd text eol=crlf
*.sln text eol=crlf
# Never touch binary files
*.png binary
*.jpg binary
*.zip binary
What each attribute does, per the gitattributes manual:
text=auto: Git decides whether a file is text. Text files get their endings normalized to LF in the repository.eol=lf/eol=crlf: the line ending to use in the working folder for those files. Settingeolalso turns ontextfor them.binary: shorthand for-diff -merge -text, so Git never converts or diffs the file.
Normalize files that were already committed
Adding .gitattributes doesn't rewrite files already in the repository. Commit or stash your other changes first, then:
git add --renormalize .
git status
git commit -m "Normalize line endings"
--renormalize re-applies the conversion rules to every tracked file, and git status lists the files whose stored endings changed. Do this in its own commit, so the line-ending change doesn't hide real edits in a review. If you have uncommitted work, stash it first.
See which files have which line endings
git ls-files --eol
Example output from a test repository:
i/lf w/lf attr/text=auto .gitattributes
i/lf w/lf attr/text=auto app.js
i/lf w/crlf attr/text=auto win.txt
i/mixed w/mixed attr/ notes.txt
i/ is the line ending stored in the index (what will be committed), w/ is the working-folder copy, and attr/ shows the attributes that apply. mixed means the file contains both LF and CRLF, which is usually worth fixing.
When the warning becomes an error
core.safecrlf controls how strict Git is. Set to true, Git rejects a file whose conversion would not round-trip to the original, and the warning becomes:
fatal: LF would be replaced by CRLF in b.js
Set to warn, Git only warns and continues. If you hit the fatal version, check git config --show-origin core.safecrlf and either add the .gitattributes rules above or relax the setting.
Should you just ignore it?
For a solo project on one operating system, ignoring the warning is fine: nothing is lost, and the committed content is still LF. In a team or a cross-platform project, add .gitattributes once. It ends the warnings, stops whole-file diffs caused by endings, and keeps shell scripts runnable on Linux. One caveat from the Git manual: conversion can corrupt a binary file that Git wrongly detects as text, which is why explicit binary lines for your binary file types are worth adding.
Frequently asked questions
- Is "LF will be replaced by CRLF" an error?
- No. It is a warning, and the git add or commit still succeeds. It tells you that a file currently has LF line endings in your working folder and that, with your current settings, Git will write it out with CRLF endings the next time it checks the file out. The copy stored in the repository is not damaged.
- Should I set core.autocrlf to true or false?
- GitHub's documentation recommends true on Windows and input on macOS and Linux. A committed .gitattributes file is a better fix for a shared project, because it applies the same rules to everyone regardless of their personal core.autocrlf setting.
- Why do I get the warning even though I never set core.autocrlf?
- On Windows it is often already set to true in Git's system-wide config file, written by the Git for Windows installer, rather than in your own settings. Run git config --show-origin --get-all core.autocrlf to see where the value comes from.
- Will the line-ending change show up as a diff for every line?
- It can, if files were committed with CRLF endings and you then enable normalization. Running git add --renormalize . once and committing the result converts them in a single commit, after which the diffs stay clean.