Tips when collaborating with git across different operating systems

Important

configuring this before we start contributing to this repo will save us lots of headaches down the road

tl;dr

Different operating systems encode the “end of a line” in text files in different ways.

git supports them all, but we must configure each of our computers correctly, to avoid messing things up for other people in our team.

Checkout that you configured your git settings according to this guide before committing files in this repo.

How to fix it

Windows users

the git setting called ‘core.autocrlf’ should be set to ‘true’

git config --global core.autocrlf true

Linux/Mac/Unix users

the git setting called ‘core.autocrlf’ should be set to ‘input’

git config --global core.autocrlf input

So… What happens if I don’t configure it correctly?

you will likely notice that LOTS of files appear to be modified, but when you go check out the differences, nothing seems to be changed.

You will also notice it, if you see this output when you run git diff

$ git diff
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in cinder-superhero/404.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in cinder-superhero/base.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in cinder-superhero/content.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in cinder-superhero/css/base.css.
[...]

This isn’t too bad until you consider the consequences: Since you are effectively changing each of the lines (the last character of the line is the line ending), git will treat that line as “modified by you”, if anyone else makes any change, git will consider that “two people changed the same line” => bring up the “Merge conflict error”.

The ultimate consequence of this is that the rest of the team will be carrying the burden of your misconfiguration.

This will result in lots more merge conflicts than normal.

For more info, check out the official doc

Authors