Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Windows AND linux line-endings

My main OS is windows 10.

I have an Ubuntu 14.04 box running in Vagrant that I develop my applications on. The box is running SMB which gives me root file access to the Ubuntu server.

On the Ubuntu server I have my application files in a GIT repo with a gitlab server as the origin.

I run SourceTree on my windows machine that connects to the ubuntu GIT repo through the SMB share (so I assume it uses my Windows GIT installation).

Git status on the ubuntu machine gives no changes.

Git status on Windows and SourceTree indicate that all the files have changed (because of the line endings).

What settings on which OS should I use in order to be able to use the same local repo on both Windows and Linux?

like image 599
Basaa Avatar asked Jan 05 '16 11:01

Basaa


People also ask

Can Windows use LF line endings?

Unfortunately, the programmers of different operating systems have represented line endings using different sequences: All versions of Microsoft Windows represent line endings as CR followed by LF. UNIX and UNIX-like operating systems (including Mac OS X) represent line endings as LF alone.

What line endings does git use?

This is a good default option. text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout.

Does Linux use LF or CRLF?

Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character.

Does Windows use CRLF or LF?

The default value on both Windows and Mac Classic clients is crlf . The crlf option enables line-end translation using the operating system's default line termination convention -- CR for Mac Classic text files, CR/LF for Windows text files.


2 Answers

On Windows:

$ git config --global core.autocrlf true

On Linux:

$ git config --global core.autocrlf input

Read more about Dealing with line endings

like image 152
Assem Avatar answered Oct 01 '22 11:10

Assem


Set the autocrlf to the desired value:

How autocrlf works:

core.autocrlf=true:    core.autocrlf=input:      core.autocrlf=false:

       repo                     repo                    repo
    /        \               /        \              /        \
crlf->lf    lf->crlf     crlf->lf       \          /            \      
 /              \        /                \      /                \

Yet another way to show how autocrlf works

1) true:             x -> LF -> CRLF
2) input:            x -> LF -> LF
3) false:            x -> x -> x
like image 37
CodeWizard Avatar answered Oct 01 '22 11:10

CodeWizard