includeIf

Conditional Configuration with includeIf

Commit to a client's repository with your personal email once and it is in their history for good. An includeIf section reads another file only when a condition holds, most often the repository's location:

A work email address for every repository under ~/workShell
git config set --global 'includeIf.gitdir:~/work/.path' '~/.gitconfig-work'
git config set --file ~/.gitconfig-work user.email sam.rivera@corp.example.com
git init -q ~/work/intranet
git config get --show-origin user.email
git -C ~/work/intranet config get --show-origin user.email
Output
file:/home/dev/v5-ch2/gitconfig sam@example.com
file:/home/dev/v5-ch2/home/.gitconfig-work      sam.rivera@corp.example.com

The global file now contains [includeIf "gitdir:~/work/"] with path = ~/.gitconfig-work. A trailing slash matches every repository below the directory; gitdir/i: ignores case (use it on Windows and macOS). Other conditions are onbranch:release/** and, since Git 2.36 1,932 , hasconfig:remote.*.url:https://git.example.com/**, which matches by remote URL wherever the clone lives.