Aaron's Blog

https://aaronchenwei.github.io/

View on GitHub
7 November 2022

Where do the settings in my Git configuration come from?

by aaronchenwei

Git checks following 4 places for a configuration files:

The settings cascade in the following order, with each file adding or overriding settings defined in the file above it.

  1. System configuration.
  2. User configuration.
  3. Repository-specific configuration.

Teach git config the --show-origin option to print the source configuration file for every printed value.

For example:

$ git config --list --show-origin
file:$HOME/.gitconfig    user.name=aaronchenwei
file:$HOME/.gitconfig    user.email=aaronchenwei@hotmail.com
file:$HOME/.gitconfig    core.autocrlf=input
file:$HOME/.gitconfig    core.safecrlf=false
file:$HOME/.gitconfig    pull.rebase=true
file:$HOME/.gitconfig    push.default=current
file:$HOME/.gitconfig    init.defaultbranch=main
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=true
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        remote.origin.url=https://github.com/aaronchenwei/aaronchenwei.github.io.git
file:.git/config        remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config        branch.main.remote=origin
file:.git/config        branch.main.merge=refs/heads/main

Since Git 2.26, you can add the --show-scope option:

$ git config -l --show-origin --show-scope