Why should I use core.autocrlftrue in Git?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
core.autocrlf=true tells Git to convert line endings between CRLF (Windows) and LF (Unix/macOS) automatically. On commit, it converts CRLF to LF so the repository stores consistent Unix-style line endings. On checkout, it converts LF back to CRLF so Windows tools display files correctly. This prevents diff noise where every line appears changed just because of line ending differences, and avoids merge conflicts caused by different developers using different operating systems. For modern projects, .gitattributes is the preferred approach, but core.autocrlf=true remains common on Windows workstations.
What Line Endings Are
Different operating systems use different characters to mark the end of a line. When a Windows developer commits a file with CRLF endings and a macOS developer opens it, tools may display extra ^M characters. When both edit the file, Git sees every line as changed even if only the line endings differ.
The Three Settings
| Setting | On Commit | On Checkout | Best For |
true | CRLF → LF | LF → CRLF | Windows developers |
input | CRLF → LF | No conversion | macOS/Linux developers |
false | No conversion | No conversion | Projects that handle endings manually |
Why Use core.autocrlf=true
With autocrlf=true, Windows developers work with CRLF locally while the repository stays LF-normalized. This prevents the "every line changed" problem in diffs.
The Better Alternative: .gitattributes
.gitattributes is committed to the repository and applies to all developers regardless of their local Git config. * text=auto detects text files and normalizes them to LF on commit, similar to autocrlf=true but enforced at the repository level.
When autocrlf Causes Problems
Checking and Fixing Line Endings
Recommended Configuration
Common Pitfalls
- Using
autocrlf=trueon Linux/macOS: This converts LF to CRLF on checkout, which breaks shell scripts and Makefiles. Useautocrlf=inputon Unix systems, or better yet, rely on.gitattributesand setautocrlf=false. - Not committing
.gitattributes:core.autocrlfis a local setting that varies per developer. Without a committed.gitattributes, new team members get whatever their default is. Always commit.gitattributesto enforce consistent behavior. - Corrupting binary files:
autocrlf=truemay modify bytes in binary files that happen to contain0x0D 0x0Asequences. Mark binary files explicitly in.gitattributeswith thebinaryattribute or-text. - Forgetting to renormalize after adding
.gitattributes: Existing files in the repository keep their old line endings until you rungit add --renormalize .and commit. Without this step, old files retain mixed endings. - Docker and CI environments ignoring local config: Build containers and CI runners often have
autocrlf=falseby default. If your repository relies onautocrlf=truefor correct line endings, scripts may fail in CI. Use.gitattributeswith expliciteol=lffor scripts instead of depending on local config.
Summary
core.autocrlf=truenormalizes line endings to LF on commit and converts to CRLF on checkout — designed for Windowscore.autocrlf=inputconverts to LF on commit without checkout conversion — designed for macOS/Linux.gitattributesis the preferred solution because it is committed to the repository and applies to all developers- Use
* text=autoin.gitattributesfor automatic text detection and normalization - Force
eol=lffor shell scripts andeol=crlffor batch files regardless of developer platform - Run
git add --renormalize .after adding.gitattributesto fix existing files in the repository

