configure line endings in git

How to Configure Line Endings in Git Commit

Git offers differential treatment for line endings of files, in Windows & Linux. It is important to set the proper line endings for your git repository if you need to make it cross platform. If you don’t set line endings for your git commits, then the repository code will not work when checked out on another platform. In this article, we will learn how to configure line endings in Git commit.


How to Configure Line Endings in Git Commit

In Linux systems, line endings are represented with Line Feed (LF) while they are represented using carriage return line feed (CRLF). There are the 3 types of settings for line endings in git.

  1. Checkout Windows style, Commit Linux style
    In this case, git will convert LF (line feed) to carriage return line feed (CRLF) while checking out files and CRLF will be converted to LF while committing files. This is the recommended setting for Windows systems. In such cases, it is advisable to set core.autocrlf to true on your Windows git system.
  2. Checkout as-is, Commit Linux style
    In this case, git will not make any changes while checking out files but convert CRLF to LF while committing files. This is the recommended settings on Linux systems to make your git repo cross platform. You need to set core.autocrlf to input on your Linux system.
  3. Checkout as-is, Commit as-is
    In this case, git will not perform any conversions during checkout or commits. For this purpose, you need to set core.autocrlf to false. In this case, the git repo will not be cross platform.

The simplest ways to configure line endings is to us git config command. Here is an example to set autocrlf to true.

$ git config --global core.autocrlf true

If you want to know the existing settings for line endings, run the following command.

$ git config --global --edit

In this article, we have learnt how to configure line endings in git.

Also read:

Git Remove File From History
Bash Loop Through Files in Directory Recursively
How to Remove .pyc file from Git Repository
How to Reset Local Git Repository to Remote
How to Fix “Cannot Access NGINX from Outside”

Leave a Reply

Your email address will not be published.