Git Configuration

Follow Us

Our Communities

Module 2 – Git Configuration

This module will introduce you to the process of setting up Git for your work, with a focus on how to configure it to match your preferences.

Git Configuration Levels

When using Git, you will have to set some configuration settings that let Git know who you are, and how you want to perform certain tasks. There are three levels of Git configuration settings:

  • System: These configurations apply system-wide, i.e., they apply to every user on the system and all their repositories. The settings are stored in /etc/gitconfig.
  • Global: These apply globally to a user, i.e., they apply to all the repositories of a particular user. The settings are stored in the ~/.gitconfig file.
  • Local: These apply to a single repository. The settings are stored in the .git/config file within the repository.

Basic Git Configuration Commands

Git provides the git config command to change the configuration settings.

  • Setting username and email: Git uses a username to associate commits with an identity. You can use the git config command to set the username and email for Git:

git config --global "Your Name"
git config --global "[email protected]"
  • Checking config settings: You can check all the configuration settings using the command git config --list. This command will list all the settings Git can find at that point.

Configuring Default Text Editor

Git allows you to use your favorite text editor. You can set the default text editor using the following command:

git config --global core.editor emacs

You can replace “emacs” with “nano”, “vim”, “sublime”, “vscode”, or whatever your preferred editor is.

Ignoring Files with .gitignore

Sometimes, you might want Git to ignore certain files or directories (like log files, binary files, etc.). This can be done by creating a file named .gitignore in the repository’s root directory. The .gitignore file should specify the files/directories to be ignored by listing them one per line. You can also use wildcards for patterns.

Exercises and Practice

Exercise 1: Set your username and email in Git and check the configuration.

Exercise 2: Change your default editor for Git to your preferred text editor.

Exercise 3: Create a .gitignore file and practice ignoring some files in a Git repository.

The exercises should give learners a chance to understand the different configuration levels in Git and apply them practically. They should also be able to set preferences, like choosing their preferred text editor and ignoring specific files or directories.

Basic on Git


Branching, Merging and Options