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
- What Is a Credit ScoreA credit score is a three-digit number, typically ranging from 300 to 850, that represents your cred…
- What Is CD rates make no sense based on length of time invested. Explain like I'm 5CD (Certificate of Deposit) rates often don't increase with longer lock-up times the way people expe…
- What is a phdA PhD (Doctor of Philosophy) is a doctoral degree earned after completing advanced academic research…
- What is a polymathA polymath is a person with deep knowledge and expertise across multiple different fields or academi…
- What is aaveAAVE stands for African American Vernacular English, a dialect with distinct grammar, pronunciation,…
- What is aarch64ARMv8-A (commonly called ARM64 or AArch64) is a 64-bit processor architecture developed by ARM Holdi…
- What is about menTopics and discussions about men typically encompass masculinity, male identity, gender roles, men's…
- What is abiturAbitur is the German academic qualification awarded upon completion of secondary education, typicall…
- What is abrosexualAbrosexual is a sexual orientation identity where a person's sexual attraction changes or fluctuates…
- What is abgABG is an Indonesian acronym standing for 'Anak Baru Gede,' which refers to adolescent girls or teen…
- What is aaaAAA batteries are a standard cylindrical battery size measuring 10.5mm in diameter and 44.5mm in len…
- What is aacAAC (Advanced Audio Codec) is a digital audio compression format that provides better sound quality …
- What is aaa gameAAA games are high-budget video games developed by large studios with budgets typically exceeding $1…
- What is a proxyA proxy is a server that acts as an intermediary between your device and the internet, forwarding yo…
- What is ableismAbleism is discrimination and prejudice against people with disabilities based on the assumption tha…
- What is absAbs, short for abdominal muscles, are the muscles in your core that flex your spine and stabilize yo…
- What is abortionAbortion is a medical procedure that ends pregnancy by removing the fetus before viability. It can b…
- What is accutaneAccutane (isotretinoin) is a powerful prescription medication derived from vitamin A used to treat s…
- What is acetaminophenAcetaminophen, also known as paracetamol, is an over-the-counter pain reliever and fever reducer use…
- What is acidAcid is a chemical substance that donates protons (hydrogen ions) to other substances, characterized…
Also in Daily Life
- How To Save Money
- Why are so many white supremacist and right wings grifters not white
- Does "I'm 20 out" mean youre 20 minutes away from where you left, or youre 20 minutes away from your destination
- Why are so many men convinced that they are ugly
- What does awol mean
- What does asl mean
- What does ad mean
- What does asap mean
- What does apex mean
- What does asmr stand for
- What does atp mean
- What causes autism
- What does abg mean
- What does am and pm mean
- What does a fox sound like
More "What Is" Questions
Trending on WhatAnswer
Browse by Topic
Browse by Question Type
Sources
- Git Documentation - Git Attributes CC-BY-3.0
- Wikipedia - Newline CC-BY-SA-4.0