Conditional Git Configuration
Building on the earlier article on automatically transforming Git URLs, I’m back with another article on a (potentially powerful) feature of Git—the ability to conditionally include Git configuration files. This means you can configure Git to be configured (and behave) differently based on certain conditions, simply by including or not including Git configuration files. Let’s look at a pretty straightforward example taken from my own workflow.
Here’s a configuration stanza from my own system-wide Git configuration:
[includeIf "gitdir:~/Work/Code/Repos/"]
path = ~/Work/Code/Repos/.gitconfig
The key here is the includeIf keyword. In this case, Git will include the referenced configuration file specified by path, if the location of the Git repository matches the path specification after gitdir. Basically, what this means is that all repositories under ~/Work/Code/Repos will trigger the inclusion of the additional configuration file.
Here’s the additional configuration file:
[user]
email = name@work-domain.com
name = Scott Lowe
[commit]
gpgsign = false
As long as I group all work-relatd repositories in the specified directory path, these values override the system-wide values. This means I can specify my work e-mail address as the e-mail Continue reading
