Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Configuration Options

core.autocrlf setting

Reference for core.autocrlf: what true, input and false do to CRLF and LF line endings on add and checkout, and why a .gitattributes file is safer.

core.autocrlf is Git's older, user-level switch for line-ending conversion. Windows editors traditionally end lines with CR LF, Linux and macOS with LF alone. Repositories shared between both are happiest when the committed blobs use LF only; autocrlf makes Git translate on the way in and, optionally, on the way out.

It takes three values. true converts CRLF to LF when files are added and LF to CRLF when they are checked out. input converts only on the way in. false, the default, converts nothing.

Terminal
git config --global core.autocrlf true     # Windows
git config --global core.autocrlf input    # Linux and macOS
git config --global core.autocrlf false    # leave bytes alone

Try it

Bash Conversion on add

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.

Bash Conversion on checkout

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.

Syntax

Terminal
git config [--global] core.autocrlf <true | input | false>
Value Add / commit Checkout
true CRLF becomes LF LF becomes CRLF
input CRLF becomes LF no change
false no change no change

git ls-files --eol shows the state: i/ is the line ending in the index, w/ in the working tree, and attr/ what .gitattributes requests.

Safety check: core.safecrlf (default warn) prints a warning when a conversion would not be reversible, and with true it refuses the operation.

Usage notes

  • Binary files are skipped. Git detects a NUL byte and leaves the file alone, but detection is a heuristic, so mark known binaries in .gitattributes.
  • A text or eol attribute overrides this setting for the matching paths. A committed .gitattributes with * text=auto gives every contributor the same behavior regardless of their personal config, and is the recommended approach.
  • input is the usual choice on Unix for people who might receive CRLF files from elsewhere; true on Windows when tools expect CRLF in the working tree.
  • Existing files are not rewritten when you change the setting. Run git add --renormalize . to update the index, and refresh the working tree with a checkout.
  • Mixed endings in one file cause "CRLF would be replaced by LF" style warnings and noisy diffs; fix the file instead of silencing Git.
  • core.eol chooses the native ending used for text files when no autocrlf rule applies (lf, crlf or native).
  • Shell scripts break with CRLF (/bin/sh^M: bad interpreter), so force *.sh text eol=lf.