Version management with Git, GitHub and Co

Git configuration: Set up name and email for your account

All videos of the tutorial Version management with Git, GitHub and Co

The use of Git as a version control system brings numerous advantages, especially for efficient collaboration on software projects. One of the first hurdles you need to overcome is setting up your identity, consisting of your name and your email address. This information is logged in the commits and allows for clear traceability when it comes to tracking changes and contacting the author of the change in case of questions. In this guide, I will show you how to correctly set up your Git configuration.

Key insights

  • Git requires your name and an email address for identification.
  • Your configuration can be set system-wide, globally, or locally for a specific repository.
  • These steps are essential to ensure that your commits are correctly attributed.

Step-by-step guide

Step 1: Understand the different configuration levels

Before you start configuring, it's important to know that Git offers three different levels for configuration files. These are:

  1. System-wide configuration: This configuration is applied for all users on the system and is located in the directory /etc/gitconfig.
  2. Global configuration: This is stored for the current user in the home directory, typically in ~/.gitconfig. It is the most common form of configuration and applies to all repositories you work on.
  3. Local configuration: This is specific to a single Git repository and is stored in the repository's directory, in the file.git/config.

To successfully set up Git, we will focus on the global configuration as it offers the simplest way to define your identity for all future repositories.

Git configuration: Set up name and email for your account

Step 2: Check your Git installation

First, you should ensure that Git is correctly installed on your system. You can easily check this by entering the following command in your terminal:

git --version

This command shows the currently installed version of Git. If Git is not installed, follow the installation instructions on the official Git website.

Step 3: Configure name and email address

Now comes the crucial part: configuring your identity. This is done using the command git config. To set your name, use the following command:

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

Replace "Your Name" with your actual name. Since Git does not return any output by default, you will not see any confirmation, but this is the normal behavior.

Git configuration: Set up name and email for your account

For the email address, proceed in the same way. Use the following command:

git config --global user.email "your.email@example.com"

Here you should provide the email address that you also use for your GitHub or other accounts, if you already have any. This email address will be linked to your commits.

Git configuration: Set up your name and email for your account

Step 4: Check your configuration

After you have configured your name and email address, it is important to verify the settings. You can do this by entering the following command:

git config --list

This command shows a list of all currently configured settings and should display your name as well as your email address. This way you ensure that everything is set up correctly.

Git Configuration: Set up name and email for your account

Step 5: Optional - Editor and other settings

In addition to your name and email address, you can also set the default text editor that Git should use. If you want to work with a specific editor, you can use this command:

git config --global core.editor "your_editor"

Replace "your_editor" with the name of the editor you prefer – for example, nano, vim, or code for Visual Studio Code. But this is optional and not necessarily required at the beginning.

Summary - One-time Git Configuration: Setting up Name and Email

To get started with Git, it is crucial to configure your identity correctly. You have learned that correctly working with Git also means setting your name and your email address. This is usually done through the global configuration and affects all projects you work on in the future. Remember to go through these steps before your first commit to ensure that your changes can be correctly attributed.

Frequently asked questions

What is the difference between global and local configuration?The global configuration applies to all repositories of the user, while the local configuration is specific to a single repository.

Do I need to set my name and email address for each repository again?No, if you set up the global configuration, it applies to all future repositories, unless you override the settings locally.

Can I change my configuration later?Yes, you can change your configuration at any time with the same git config commands.

Why is there no output after the configuration?This is the default behavior of Git. As long as no error occurs, the command is considered successfully executed.