How to provide custom Git configuration for different projects

Git provides an option to load different configurations based on path of repositories. It uses includeIf sections in ~/.gitconfig file, which allow you to include config directives from another source.

Let's assume your projects are grouped by "parent" directories, like directory called company-a contains all projects related to company-a, etc. Therefore, all settings inside that path will be additionally applied from .gitconfig-company-a.

[user]
    email = contact@grzegorzwozniak.com
    name = Grzegorz Wozniak

[includeIf "gitdir:~/dev/company-a"]
    path = .gitconfig-company-a
    
[includeIf "gitdir:~/dev/company-b]
    path = .gitconfig-company-b

[includeIf "gitdir:~/dev/os"]
    path = .gitconfig-os
~/.gitconfig
[user]
    email = contact@company-a.com
    name = Grzegorz Woźniak
~/.gitconfig-company-a
[user]
    email = contact@company-b.com
    name = GW
~/.gitconfig-company-b
[user]
    email = opensource@grzegorzwozniak.com
    name = Grzegorz Wozniak
~/.gitconfig-os