git config --global core.autocrlf false
git config --global core.eol lf
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
After above configuration, you might want git to normalize all the files in the repo. To do this, go to to the root of your repo and run these commands:
git rm --cached -rf .
git diff --cached --name-only -z | xargs -n 50 -0 git add -f
git ls-files -z | xargs -0 rm
git checkout .
Now just be sure that all of your text editors and IDEs use LF and UTF-8.
You can switch to CRLF for a single repository without changing the global settings. Git will handle the LF convertion thanks to the .gitattributes file.
git config core.eol crlf
Define your custom coding styles using EditorConfig files:
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true