Git has several levels of configuration: System wide, per user, per repository and finally, on each individual command invocation. If a values is defined on several levels, the most specific counts.
Configuration files can include other files with
includeIf. The included files behave as if the configuration they contain had been written in the including file.
includeIf includes files conditionally. Right now, it only supports one attribute,
gitdir: “The data that follows the keyword gitdir: is used as a glob pattern. If the location of the .git directory matches the pattern, the include condition is met.”
Depending on the directory your repo is in, you can pull in different configuration files. That comes in very handy to configure different a different username and email address, for example to differentiate between work and play (taken directly from the release notes):
Put this into your user specific
[includeIf "gitdir:~/work/"] path = .gitconfig-work [includeIf "gitdir:~/play/"] path = .gitconfig-play
And create additional
.gitconfig-play (the files can reside wherever you want, you can use a full path as well:
[user] name = Serious Q. Programmer email = firstname.lastname@example.org
[user] name = Random J. Hacker email = email@example.com
Did you like this article? You can invite me on a coffee ☕️ if you like.