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 "newline" code so your text jumps to the next line. The tricky part is that different operating systems use different codes for that newline: 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 Linux-style line endings).

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 you're in the repository you want to adjust.

Task

Set your line ending treatment configuration.

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

Next step
Wanna try the Story mode?
Take the course as it was meant to be taken: bite-sized progression, focused linear order, gradually unlock Gitopedia entries. Continue with real Git in VS Code/Cursor at any time.
Story mode
FREE
but requires sign-in
© 2024-2026 GitByBit.All rights reserved.