There are two git config attributes that affect the line endings: core.autocrlf
and core.eol
.
Previously, you were told to use core.autocrlf = true
to be able to work on cross-platform projects, but it's not true
any more.
If your system/IDE/tooling support LF
and you do want to use LF
as everyone else in your team without any silent lf->crlf->lf
normalizations, you must turn off autocrlf
and configure eol
to not infer native
line endings, but force it to use lf
.
Now there are two ways to achieve LF
in all your files a/o repos:
- Globally for all repositories on your local machine.
- Per-repository via checked-in
.gitattributes
file.
This file overrides any local configuration for everyone who clones the repo.
I personally recommend to go with both for all local repos and to ensure cross-platform cross-dev consistency.
1) Globally for all repositories on your local machine
Being in your working directory (your local repo):
First commit everything
Let's be paranoid a bit and set it both globally and in repo as well. Just in case.
git config --global core.eol lf
git config --global core.autocrlf false
git config core.eol lf
git config core.autocrlf false
Delete everything "code" except .git
.
You can also omit dependencies, installed files (such as node_modules
), build files and any git-ignored file as well.
and lastly run
git reset --hard HEAD
Things should be working now. Newly checked files should follow the new configuration and keep whatever line-endings were cloned from the remote repo.
Note that if your remote repo uses mix of crlf
lf
endings, you will also have to run and push
git add --renormalize .
2) Per-repository via checked-in .gitattributes
file
Being in your working directory (your local repo):
Create .gitattributes
file in the root with this content:
* text=auto eol=lf
Commit the file (and everything else)
Same as above
Same as above
IMPORTANT NOTE: After you introduce the file into the repository, it is necessary that everyone who still has old CRLF files does step 3 and 4 to update their working directory as just checking out the commit doesn't affect already existing files.

Notes
setting core.autocrlf
to true
or input
overrides core.eol
https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-coreautocrlf
core.autocrlf = input
is the preferred value on unix systems.
https://stackoverflow.com/a/41282375/985454
https://stackoverflow.com/a/4425433/985454
Troubleshooting
Reinstall git for windows with third option (as in the screenshot in Q)
Checkout as is - Commit as is (core.autocrlf = false
)