My favoured option is the third one Checkout as-is, commit as-is
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
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
It has taken me a long frustrating time to get around to understanding line endings in cross platform projects!