50

I'm trying to figure out what is the default value for core.autocrlf in Git if the user doesn't change this setting.

I've looked in the docs but can't find this info. Can you please point me in the right direction?

Specifically, on a fresh Git install, would Git automatically convert Windows line endings to Unix when committing to a repo from a Windows system?

Thanks!

Christoffer Lette
  • 14,346
  • 7
  • 50
  • 58
Pensierinmusica
  • 6,404
  • 9
  • 40
  • 58
  • 4
    Documentation on https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration lists three options but doesn't say which is default, and on my clean install on Ubuntu `git config --list` gives no entry for `autocrlf`, `git config --get autocrlf` returns `error: key does not contain a section: autocrlf`, so I'm posting a bounty. Presumably this means default is false but it'd be good to have this confirmed – user56reinstatemonica8 Jan 12 '18 at 10:56

5 Answers5

52

Checking the git source code, core.autocrlf is set to false by default. (And has been since the property's original introduction on Feb 13, 2007, though it has since been converted from a static value to a constant.)

The Windows installer does require you to pick a value for this property which is explicitly set in the git system config.

LightBender
  • 4,046
  • 1
  • 15
  • 31
  • 9
    Actually it doesn't set it in the 'system config'. It sets it in the (Windows specific) anomalous ProgramData config file. This functions as a sort of 'all users' or 'all apps' settings file (it can be shared by multiple git apps), and is located at '\ProgramData\Git\config'. There is no flag for accessing it at the command line. – Tom Aug 28 '19 at 18:54
  • For me, it was in a gitconfig file in C:\Users\{myusername}\AppData\Local\Programs\Git\etc See: https://stackoverflow.com/a/42934458/605597 – KevinVictor Jan 24 '22 at 20:33
13

It is difficult to find this stated but I could figure out by trial and error that:

  • the default value is "false"

  • Windows installer let you choose the desired behavior but by default (if you install without changing proposed settings) it sets it to "true". This is not the software default, the installer sets the core.autocrlf system setting.

"false" means no processing on line endings "true" means checking in as LF and checking out according to system (CRLF on Windows and LF on Unix).

When Unix and Windows are both used it is advisable to use "false" on Unix (because automatic conversion can break some binary files that looks like text files and Unix uses LF anyway) and "true" on Windows (otherwise the repository is filled with CRLF which is causing compatibility issues).

Marcel Gosselin
  • 4,610
  • 2
  • 31
  • 54
Claudio
  • 156
  • 1
  • 4
1

You can list all config key-values by issuing this command

git config --list

And as I see the default is

core.autocrlf=true

Although this is the setting I chose(or better to say "not touched") when I was installing Git for Windows

Dmitriy
  • 5,357
  • 8
  • 45
  • 57
  • 3
    `git config --list` only displays values that have been explicitly set. At the moment there doesn't seem to be a way to get the default value of a git config option. See [this answer](https://stackoverflow.com/a/33720449/266309) for more details. – waldyrious Oct 09 '17 at 08:42
  • @waldyrious what if it hasn't been explicitly set? And if it is always explicitly set by default and hasn't been set since then this would work. e.g. I have never set autocrlf and I see it listed there with a value, so that is the default value in my git install, core.autocrlf=true – barlop Oct 29 '17 at 23:05
  • 1
    Why the downvotes? I just checked that this indeed is the case (git version 2.15.0.windows.1). If I delete my global `.gitattributes`, `git config --list`shows `core.autocrlf=true`. If I set it to `false` then this new setting appears as the last line in the output and thus overrides the default. – user2061057 Nov 24 '17 at 09:22
-1

If you're using the newest window installer of git, the default option of core.autoclrf is false .

Sanster
  • 1,068
  • 1
  • 9
  • 12
-1

Apart from wanting to know what the software default is when not explicitly set, you also can have different configuration per repo.

So the most useful way to find out your config and/or confirm your desired behaviour is to run:

git config core.autocrlf

teebszet
  • 451
  • 1
  • 5
  • 12
  • for me this command outputs nothing, since nothing has been set. how does that help? – eis Sep 07 '21 at 12:07
  • edited my answer to be clearer on what I meant. if nothing is set, then is likely false, according to accepted answer – teebszet Sep 09 '21 at 02:32