Git line endings on Windows with Cygwin / WSL

When using Git on Windows with Cygwin or Windows Subsystem for Linux, CRLF conflicts can falsely make a Git repo dirty. From Cygwin or WSL with line ending clashes, “git diff” will show ^M at the end of each line and fail merge on “git pull”. This can cause missed code changes or needless commits. We suggest to force LF line endings no matter what environment the user is in. Even Windows Notepad supports LF line endings.

git config --global core.autocrlf false

git config --global core.eol lf

This tells Git to use line endings \n on committed files. Use pre-commit to check for LF line endings before committing.

To cleanup mixed repository mixed line endings use dos2unix and mac2unix recursively and make a Git commit just for those changes.


To disregard line endings for diff and patch:

diff -Naur --strip-trailing-cr old.txt new.txt