2. Setting up Git

Configuring line endings treatment

Text files are just lists of characters, and computers save every character using a code under the hood. Hitting the Enter key stores a special "new line" code so your text jumps to the next line. The tricky part is that different operating systems picked different codes for that new line: Windows uses one combination, while Linux and macOS use another. That's why a file created on one system can look odd on another.

To this day it remains a source of confusion. Say, you created a file on Linux and sent it to your friend, who uses Windows. All they see is a solid wall of text, because Windows doesn't recognize Linux's line breaks.

VS Code line ending treatment for a particular file

How is this relevant to Git?

When it comes to Git, the problem quickly escalates once a team collaborates remotely on their own devices. One teammate may commit from Windows, another from macOS or Linux, so the repository needs a consistent format. The common workaround is to let everyone edit files with whatever line endings their system prefers, but normalize them when saving to the repository (usually to the Linux-style line ending).

If you really want to understand what's going on with these settings, read the official Git documentation on core.autocrlf and core.safecrlf. If you're just getting started, stick with the sane defaults we walk through below.

So, what's next?

Please follow the instructions below, depending on your operating system. You're using macOSLinuxWindows.

If you're on Linux/macOS (our case)(not our case), run this to keep your line endings in order:

git config --global core.autocrlf input
git config --global core.safecrlf warn

The --global option sets the default Git settings used in repositories on your computer. However, these values can be overridden per repository—just run the needed git config without the --global option while being in the repository you want to adjust.

Task

Set your line ending treatment configuration.

Great, let's move on to the final piece of config we must set before using Git.

Next step
© 2024-2025 GitByBit.All rights reserved.