What is lf and crlf in git

Last updated: April 1, 2026

Quick Answer: LF (Line Feed) and CRLF (Carriage Return + Line Feed) are different line ending conventions in text files. LF is used on Unix/Linux/Mac systems, while CRLF is used on Windows. Git can automatically convert between these formats to prevent repository inconsistencies.

Key Facts

Understanding Line Endings

Line endings are invisible characters that mark the end of lines in text files. Different operating systems have historically used different conventions for representing line breaks. This difference, while seemingly minor, can cause significant issues in shared Git repositories where developers use different operating systems.

LF - Unix/Linux Line Endings

LF (Line Feed) is represented by a single character with the ASCII code 10, written as \n in programming. Unix, Linux, and modern macOS systems use LF for line endings. This convention became the standard for most programming and web development because early Unix systems adopted it. When you create files on Unix-like systems, each line automatically ends with LF.

CRLF - Windows Line Endings

CRLF (Carriage Return + Line Feed) consists of two characters: CR (\r, ASCII 13) followed by LF (\n, ASCII 10). Windows systems use CRLF for line endings due to historical compatibility with old typewriter-style carriage return mechanics. When you create files on Windows, each line ends with both CR and LF characters.

Problems with Mixed Line Endings

When developers using different operating systems commit files to the same Git repository, inconsistent line endings emerge. A file committed on Windows with CRLF may appear to have changes throughout when opened and resaved on a Linux system with LF. This can cause merge conflicts, make diffs harder to read, and create unnecessary commits. The version control history becomes polluted with line-ending changes unrelated to actual content modifications.

Git's Solution: core.autocrlf

Git provides the core.autocrlf setting to handle line ending conversion automatically. When set to 'true' on Windows, Git converts CRLF to LF when committing and converts LF back to CRLF when checking out files. On Unix systems, it typically remains 'false' since the native format matches the repository standard. The .gitattributes file can also specify line ending behavior for specific files or patterns.

Best Practices

Most modern projects standardize on LF line endings in the repository for consistency across all platforms. Using a .gitattributes file with 'text eol=lf' ensures all text files maintain consistent line endings regardless of contributor operating systems. This approach prevents line-ending related issues and keeps Git history clean.

AspectLF (\n)CRLF (\r\n)
Character Count1 character2 characters
Operating SystemUnix, Linux, macOSWindows
ASCII Value1013 + 10
Git DefaultPreferred standardConverted to LF
Repository UsageMost common in version controlConverted by core.autocrlf

Related Questions

How do I configure Git's line ending handling?

Use 'git config core.autocrlf' to set your preference: 'true' on Windows (converts CRLF to LF), 'input' on Mac/Linux, or 'false' if you want no conversion. For team consistency, use a .gitattributes file with 'text eol=lf' to enforce line endings across all platforms.

Why does my file show as changed when I only pulled it?

This typically happens when line endings differ between your system and the repository. The file appears modified even though content hasn't changed. Configure core.autocrlf or use .gitattributes to normalize line endings and resolve this issue.

What is the .gitattributes file and how does it handle line endings?

The .gitattributes file is a configuration file in a Git repository that specifies how Git should handle specific file types. It can enforce line ending conventions using 'text eol=lf', ensuring all developers commit files with consistent line endings regardless of their operating system.

Sources

  1. Git Documentation - Git Attributes CC-BY-3.0
  2. Wikipedia - Newline CC-BY-SA-4.0