Configuring Git

The first time we use Git we need to configure a few settings:

  • Name
  • Email
  • Default Editor
  • Line Ending

Settings can be specified at three different levels

  • System: settings at the system level apply to all users of the computer.
  • Global: the settings here apply to all repositories of the current user.
  • Local: the settings here apply to the current repository.

To configure the settings, open the Git Bash (Bash = "Bourne Again Shell") or Terminal. You can specify the name with:

git config --global user.name "User Name"

Now do the same for the user email:

git config --global user.email user@email.com

For the editor we'll use Visual Studio Code:

git config --global core.editor "code --wait"

All these configuration settings are stored in a text file that we can access and edit with our default editor. You can open it with:

git config --global -e

This will open the .gitconfig file where you can edit configurations. When you go back to Git Bash you'll see a message that says

hint: Waiting for your editor to close the file...

Just go ahead and close the file in VSCode.

Now we need to configure how Git will handle the end-of-line. On Windows, the end-of-line are marked with two special characters: \r for Carriage Return, and \n for Line Feed. On macOS and Linux, the end-of-line is indicated with \n. We have to configure a property called core.autocrlf. On Windows use:

git config --global core.autocrlf true

On macOS or Linux use:

git config --global core.autocrlf input