Fix the LF / CRLF line-ending warnings on Windows
safe intermediate #crlf#lf#line endings#autocrlf#windows
When to use this: Git prints LF will be replaced by CRLF, or whole files look changed when you only touched one line.
Before you start
Steps
-
Check your current setting
terminalgit config --get core.autocrlfGit for Windows normally installs with
true(convert to LF on commit, CRLF on checkout). -
Set it if it is empty
terminalgit config --global core.autocrlf trueKeeps repositories LF and your files CRLF automatically.
-
Make the repo itself decide with `.gitattributes`
PowerShellGit BashSet-Content -Path .gitattributes -Value "* text=auto"echo '* text=auto' > .gitattributesA committed
.gitattributesworks the same for every computer, so settings no longer depend on each machine. -
Renormalize files already in the repo
terminalgit add --renormalize . git statusRe-applies the rule to tracked files. Review the list, commit it as a single 'Normalize line endings' commit.
How to verify it worked
- The warnings stop and
git diffshows only real edits.
Common errors and fixes
Shell scripts fail with
bad interpreter: /bin/bash^M The script has CRLF endings. Add *.sh text eol=lf to .gitattributes and renormalize. Q&A
Is the warning an error?
No. It only tells you Git will convert line endings when it next touches the file. It is harmless but noisy.