What is lf and crlf in git
Last updated: April 1, 2026
Key Facts
- LF is a single character (\n) that marks line endings on Unix, Linux, and modern macOS systems
- CRLF consists of two characters (\r\n) that mark line endings on Windows systems
- Different operating systems use different line ending conventions for historical reasons
- Git's core.autocrlf setting automatically converts line endings between systems
- Mixing line endings in the same repository can cause merge conflicts and display issues
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.
| Aspect | LF (\n) | CRLF (\r\n) |
|---|---|---|
| Character Count | 1 character | 2 characters |
| Operating System | Unix, Linux, macOS | Windows |
| ASCII Value | 10 | 13 + 10 |
| Git Default | Preferred standard | Converted to LF |
| Repository Usage | Most common in version control | Converted 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.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Git Documentation - Git AttributesCC-BY-3.0
- Wikipedia - NewlineCC-BY-SA-4.0