When and why would you use git config command?

Experience Level: Mid-level
Tags: Git

Answer

The git config command is used for managing git configuration settings.

  • All configuration settings are stored in a text file .gitconfig.
  • The file consist of sections and key-value pairs where each key defines one property and value defines its value.
  • There are multiple levels of configuration - System/Global/Local

 

Important configuration settings

  • user.name - defines user name that will be used as an identifier of the person who committed the changes (Author)
  • user.email - defines e-mail of a person who committed the changes (Author) - this e-mail will be visible in list of commits.
  • core.editor - defines path to custom file editor

Configuration levels

  • System - configuration settings from this level are used across all user acounts on the computer.
  • Global - configuration settings from this level are used for all repositories within a useraccount
  • Local - configuration settings from this level are used for one repository only.

The configuration settings are inherited fromt he highest level (System) to the lowest level (Local). Each configuration setting can be overridden on the lower level.

There is one .gitconfig file for each configuration level, each file is stored in different location depending on the operating system and level

Related Git job interview questions
Git for beginners
Git for beginners

Are you learning Git? Try our test we designed to help you progress faster.

Test yourself