Git

git – How to Change Line-ending Settings

On Git, when the user presses the “Enter” key to return access to the keyboard, they insert an invisible character known as “line-ending”. Sometimes, Git developers encounter warnings or errors when executing the commands for performing different tasks, such as generating or tracking files/folders in the Git local repositories. More specifically, the “warning: in the working copy of ‘<repo-name/file-name>’. LF will be replaced by CRLF the next time Git touches it” is the most commonly occurred warning while tracking files from the working area to the staging area.

Developers are permitted to change the value of the Git configuration variable using the “git config” along with the “core.autocrlf” variable value as the “<false>” command to avoid the previously discussed warning.

This guide will explain the method of changing the line-ending settings on Git.

How to Change Line-ending Settings?

To change line-ending settings on Git, try the below-given instructions:

Step 1: Move to Local Repository

First, run the “cd” command along with the desired repository path and move to it:

$ cd "C:\Users\nazma\Git\naz-test"

Step 2: Generate and Update File

Next, create and update the text file simultaneously by running the “echo“ command:

$ echo "my first file" > file1.txt

Step 3: Track Changes

Then, run the following command to stage all added changes to the Git staging index:

$ git add .

Here, when we tried to add all changes to the staging area, a “warning: in the working copy of ‘naz-test/file1.txt’. LF will be replaced by CRLF the next time Git touches it” showed up:

Step 4: Check Line-ending Settings

Then, run the “git config” command to view the default settings of the line-ending:

$ git config --global core.autocrlf

According to the below-given output, the value of the “core-autocrlf” is set as “true”:

Step 5: Change core.autocrlf Value

Next, change the value of the “core.autocrlf” “true” to “false” through the provided command:

$ git config --global core.autocrlf false

Step 6: Ensure Changed core.autocrlf Value

After that, run the following command to ensure the changed value is added successfully or not to the configuration file:

$ git config --global core.autocrlf

It can be observed that the default value has been changed to “false” successfully:

Step 7: Add Changes

Lastly, execute the “git add .” command to track all added changes to the staging area:

$ git add .

As you can see, the changes are successfully tracked from the working area:

That’s all! We have effectively compiled the procedure for changing line-ending settings on Git.

Conclusion

To change line-ending settings on Git, first, move to the particular Git repository. Then, create and update the text file simultaneously. Next, track changes to the staging area. After that, change the line-ending settings, and run the “git config –global core.autocrlf “true/false”” command. This guide illustrated the procedure of changing the line-ending settings on Git.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.