Skip to content

Setting up Git

Overview

In the following, we perform the minimal initial Git setup.

Tips for instructors
  • Besides the initial Git setup, the goal is to get participants started to work with Git on the shell. For that reason:
    • Please make sure that you present slow enough in the beginning.
    • Please explain the usual git command template: git <subcommand = verb representing what you want Git to do> <options>.
    • Please explain that every subcommand has a built-in help: git <subcommand> -h or git <subcommand> --help (Web browser).

Checkpoints:

  • Please make sure that everyone successfully configured his/her username and email address.

Set your default username and email address

At least, we have to tell Git about our identity because this information is later associated with our commits. Git uses the username and email address settings to represent your identity when creating commits:

  • git config --global user.name "Last name, first name" - Sets the default username that Git associates with your commits. This options represents your real name or pseudonym which you use. It does not represent your user account on collaboration platforms such as GitLab or GitHub.
  • git config --global user.email "name@organization.org" - Sets the default email address that Git associates with your commits. Collaboration platforms such as GitLab and GitHub usually use this information to map commits to user accounts.
  • git config --global --list - Displays the default configuration settings. Here you should find your defined username and email address.

Configure username and email consistently

Your username and email address are part of the version history of your repository. Please make sure that you configured them consistently across your (client) systems. Usually, you do not want to change this information later because changing it potentially breaks the version history for your collaborators.

How are configuration settings handled in Git?

Git maintains three levels of configuration settings:

  • System level: These settings are defined on installation time and represent useful default settings for your operating system.
  • Global level: Represents your user-specific default settings. They are stored in the file .gitconfig which is usually located in your user home directory and are kept even after Git client updates. We recommend to set and change these settings via git config --global instead of editing the file directly.
  • Repository level: Represents the settings for a specific repository. You can set them via git config and have to issue these commands inside the repository directory.

You can specify a setting on multiple levels. In such a case, Git uses the setting defined on the lowest level. For example, you defined your default username you on the global level and you-special for the special Git repository. If you work in the special repository, Git will use the username you-special. In all other repositories, Git uses the username you.

Find out more about the Git configuration settings

Key points

  • Please define your identity metadata (username, email address) when you use Git on a new system.
  • Please make sure that you consistently use your identity metadata across different client systems.