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

  1. Check your current setting

    terminal
    git config --get core.autocrlf

    Git for Windows normally installs with true (convert to LF on commit, CRLF on checkout).

  2. Set it if it is empty

    terminal
    git config --global core.autocrlf true

    Keeps repositories LF and your files CRLF automatically.

  3. Make the repo itself decide with `.gitattributes`

    PowerShellGit Bash
    Set-Content -Path .gitattributes -Value "* text=auto"echo '* text=auto' > .gitattributes

    A committed .gitattributes works the same for every computer, so settings no longer depend on each machine.

  4. Renormalize files already in the repo

    terminal
    git add --renormalize .
    git status

    Re-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 diff shows 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.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.