git line ending warning (CRLF / LF) — how to fix
Quick Answer
# Linux / macOS — convert CRLF to LF on commit, never on checkout
git config --global core.autocrlf input
# Windows — convert LF to CRLF on checkout, back to LF on commit
git config --global core.autocrlf true
When this happens
warning: LF will be replaced by CRLF in src/app.ts.
The file will have its original line endings in your working directory.
Git is converting line endings because core.autocrlf is set to true on a non-Windows machine, or vice versa.
Other causes & fixes
Use .gitattributes for consistent cross-platform settings
A .gitattributes file enforces line endings regardless of individual developer settings.
# .gitattributes
* text=auto eol=lf
*.bat text eol=crlf
Normalize existing files in the repository
git add --renormalize .
git commit -m "normalize line endings"
Disable warnings (not recommended)
git config --global core.safecrlf false
Related