Git Reference ยท Concepts
Line endings (CRLF and LF)
Handle CRLF and LF line endings in Git: how core.autocrlf, core.eol and .gitattributes text settings work, and how to normalize a repository.
Windows ends text lines with two characters (CRLF, \r\n); Linux and macOS use one (LF, \n). In a team that mixes systems, files can flip between the two, producing diffs where every line appears changed, or scripts that fail with bad interpreter: /bin/sh^M.
Git solves this by normalizing: it can store text files with LF in the repository and convert to the platform's ending when writing the working tree. The modern, reliable way to control it is a .gitattributes file committed with the project, which gives every contributor the same behavior. The older per-user setting is core.autocrlf.
# .gitattributes * text=auto *.sh text eol=lf *.bat text eol=crlf *.png binary
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Settings
| Setting | Effect |
|---|---|
core.autocrlf=true |
convert CRLF to LF on commit, LF to CRLF on checkout (typical for Windows) |
core.autocrlf=input |
convert CRLF to LF on commit, never convert on checkout (typical for Linux/macOS) |
core.autocrlf=false |
no conversion |
core.eol=lf or crlf or native |
working-tree ending for files marked text |
core.safecrlf=true or warn |
warn or fail when a conversion would not round-trip |
text / text=auto / -text / binary |
attribute: always treat as text, let Git detect, never convert |
eol=lf / eol=crlf |
attribute: working-tree ending for this path, whatever the platform |
Attributes win over core.autocrlf. text=auto lets Git decide per file whether the content looks like text; use binary (or -text) for files that must never be touched.
Usage notes
- Commit
.gitattributesfirst, then normalize existing files withgit add --renormalize .and commit the result in a dedicated commit. Blame can skip it withgit blame --ignore-rev. - Check what Git thinks.
git ls-files --eolshowsi/(index) andw/(working tree) endings and the attribute applied to each path. - Warnings such as "LF will be replaced by CRLF the next time Git touches it" are informational. They show up when a conversion will happen, not when something is broken.
- Shell scripts and Makefiles must keep LF on every platform; mark them
eol=lf. Windows batch files expect CRLF. - Mixed endings inside one file are not normalized when
text=autoconsiders the file ambiguous; fix such files by hand first. - Editors matter. An
.editorconfigwithend_of_linestops editors from reintroducing the wrong ending. - Binary files (images, archives) must never be converted. If a file was corrupted by conversion, mark it
binaryand recommit it. - Whitespace checks treat a trailing CR as an error unless
core.whitespace=cr-at-eolis set (see core.whitespace).