Configuring Git

We can configure Git using the git config command. This command will manipulate the .git/config file on our behalf. In fact, if we print the content of the .git/config file, you'll see that it is similar to the output of the git config command:

$ cd ~/projects/hobnob/
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true

$ git config --list --local
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
Feel free to examine the .git directory using a tool such as  tree. First, install tree by running sudo apt install tree. Then, run tree ~/projects/hobnob/.git.

To configure Git, we must first understand that there are three scopes, or levels, of configurations, each with a corresponding configuration file stored at different locations:

  • Local: Applies only to the current repository; the configuration file is stored at <repository-root>/.git/config.
  • Global: Applies to all repositories under the user's home directory; the configuration file is stored at $HOME/.config/git/config and/or at $HOME/.gitconfig, with the latter being only available in newer versions of Git. $HOME/.gitconfig will override $HOME/.config/git/config.
  • System: Applies to all repositories in your machine; the configuration file stored at /etc/gitconfig.

The local configuration settings will override the global settings, which, in turn, override the system settings.