Git - LF Will Be Replaced by CRLF
LF stands for Line Feed
which is a way to represent the end of a line in UNIX-based systems. But in a Windows-based system, a line is usually expressed by CR (Carriage Return) and a line feed (LF).
This problem arises if you use UNIX based system (macOS) to push code, the code will have an LF ending.
If you use a windows machine, make modifications to the code, and do commit, it will be replaced by CRLF since git is smart and does not expect you to use LF on Windows OS.
Similarly, the opposite happens if the warning says, CRLF will be replaced by LF
. You will lose windows based CRLF after commit/checkout, and LF will replace it.
Fix LF Will Be Replaced by CRLF
Warning in Git
One way to fix the warning is to make changes in config files located in the path where git is installed. The value of code.autocrlf
is stored in gitconfig
file located at %ProgramFiles(x86)%\git\etc\gitconfig
or ProgramFiles\git\etc\gitconfig
and in /etc/gitconfig
in Linux/Unix based operating systems.
However, we can fix the issue in different situations:
If you wish to use the project on Unix based OS, you should set the value of core.autocrlf
to true
If you wish to use the project under Windows only, the flag should be set to false
.
However, in Unix-based OS, you can disable the core.autocrlf
per our need.
Before making modifications, you can check the current settings by using the following command,
git config core.autocrlf
The command will give output of true
or false
or input
, and you can make changes according to your need.
Fix LF Will Be Replaced by CRLF
Warning on the Whole System
To fix the issue systemwide, you can use,
git config --system core.autocrlf false
Fix LF Will Be Replaced by CRLF
Warning Per User
To fix the issue according to the user, you can use,
git config --global core.autocrlf false
Fix LF Will Be Replaced by CRLF
Warning on the Project Only
To fix the issue for a particular project,
git config --local core.autocrlf false