Line Endings ignore in Git
My favoured option is the third one Checkout as-is, commit as-is
I use Bash shell .sh
scripts in my Windows projects to automate Infrastructure as Code, then run these scripts using Windows Subsystem for Linux - WSL
I need to make sure the line endings of my Bash scripts are in the Unix style LF or \n
and not Windows CFLF or \r\n
Use Sed to fix line endings
In Bash on WSL use Sed to change all line endings to Unix style LF in all .sh files
sed -i 's/\r$//' *.sh
This is quick way to get things working, however it is worth the time taken to make sure you fix these properly in Git across all your machines.
Set Global Config in Git
If you are not sure what setting you pressed when installing Git for Windows (the screen show in the image above):
# View current settings
git config --global --edit
# Change to not perform any conversions
git config --global core.autocrlf false
More detail in this Stack Overflow answer
Set in repository .gitattributes
A repository level text will override a global autocrlf
# Set default behavior to automatically normalize line endings.
# NO We don't want this!! LEAVE line endings alone
# * text=auto
# Bash shell scripts make sure to keep unix line endings
/infra/* text eol=lf
More detail in this Stack Overflow answer and Edward Thmomson discussion in more detail
It has taken me a long frustrating time to get around to understanding line endings in cross platform projects!