Hero Image

Conditional includes in .git/config files


When maintaining multiple git repositories in the same project scope, it is cumbersome to have the same setting be applied to each of the .git/config files.

Assume the following directory tree:



If you want to, e.g. share a x.509 certificate for authentication between all customerA projects, you would have to add the corresponding section to each of the .git/config files:

sslKey = ~/.ssh/customerA/x509.key
sslCert = ~/.ssh/customerA/x509.crt


Git provides the include and includeIf section, which can be applied to the .gitconfig in your home directory. includeIf is applied by the git, if the current working directory matches the configured path.

Instead of adding the [http] section to each .git/config file, you can use the following line in your ~/.gitconfig file:

[includeIf "gitdir:~/customerA/**/**"]
path = ~/customerA/customer-git-config

Add the [http] section to ~/customerA/customer-git-config and all git settings below ~/customerA are automatically applied to each git repository.


  • You can also use the onbranch: argument, if you want to include a different config based upon the active branch of the current git project.
  • includeIf inserts the content of the included file immediately. You can use mulitple includeIf statements.