This article will discuss the “warning: LF will be replaced by CRLF” and provide the solution to fix it.
What is “warning: LF will be replaced by CRLF” in Git?
The “warning: LF will be replaced by CRLF” mostly occurs when the value of the Git configuration variable is settled as “true”. The reason behind the warning is that the committed files are different from what you saved.
So, to resolve or avoid this warning, you have to change the value of the Git configuration variable using the “$ git config <–global or local> core.autocrlf false” command.
Check out the below-given scenario, which shows us the specified warning.
Step 1: Navigate to Git Folder
First, move to the Git projects root folder using provided command:
Step 2: Create and Move to Git Local Repository
Create a new directory by executing the “mkdir” command and immediately move to it utilizing “cd” command:
Step 3: Initialize Git Repository
Now, run the “git init” command to initialize the Git local repository:
Step 4: Open and Update File
Run the provided command to create a new file and add some text using the redirect operator:
Here, we have added “It’s my first file” text in “file1.txt” through “echo” command:
Step 5: Add File
Next, add the file to the Git staging area using below command:
It can be seen that Git bash threw the mentioned warning when we tried to add the file to the staging area:
Now, let’s move to the next section to fix the “warning: LF will be replaced by CRLF”.
How to Fix “warning: Lf will be replaced by CRLF”?
Now, let’s move toward the below-provided steps to fix the stated warning encountered in the previous section.
Step 1: Check Settings
First, check the default settings of the Git configuration variable value using the provided command:
According to the below output, the Git configuration variable is set as “true”:
Step 2: Replace by CRLF Warning Globally(Per User)
Next, we will change the value of the Git configuration variable to “false” with the help of given command:
Step 3: Verify Settings
Now, we will verify the performed operation to ensure the configuration variable value is changed to “false”:
Below-output indicates that the variable value is successfully set to “false”:
Step 4: Replace by CRLF Warning Locally(For the Project Only)
To replace the CRLF warning for the specific local projects, execute the below provided command:
Step 5: Verify Settings
Now, we will run the “git config” command with “core.autocrlf” Git configuration variable to check its configured value:
In the below output, you can see that value is successfully settled to “false”:
Step 6: Add File
Finally, we will add the file to the Git staging area with the help of the given command:
It can be seen that; the file is added successfully:
Step 7: Check Status
Lastly, we will check the Git repository’s current status:
The below output indicates that the new file is added to the Git repository:
That’s it! We have provided the simplest solution to fix the CRLF warning in Git.
Conclusion
Git users mostly encounter the “warning: LF will be replaced by CRLF” when the “autocrlf” Git configuration variable value is configured as “true”. However, you can change its value as “global” per user as well as “local” per project in the “$ git config <–global or local> core.autocrlf false” command. In this article, we have discussed the “warning: LF will be replaced by CRLF” and offered the solutions to fix it.