https://blog.scottlowe.org/2023/12/15/conditional-git-configuration/ [ ] Orbits Original, technical content centered around cloud computing, Kubernetes, Linux, and networking Home About Site Archives Post Categories Content Tags (c) 2005-2024. All rights reserved. Scott's Weblog The weblog of an IT pro focusing on cloud computing, Kubernetes, Linux, containers, and networking Conditional Git Configuration Published on 15 Dec 2023 * Filed in Explanation * 304 words (estimated 2 minutes to read) 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 address to be associated with commits to work-related repositories while all others use a different e-mail address. This configuration also allows me to disable GPG signing of commits for work-related repositories (i.e., repositories in the specified path), since I don't have a GPG key associated with my work e-mail address. Could you do this with per-repository configuration settings? Absolutely. This configuration mechanism allows you to apply configuration settings to groups of repositories based on their filesystem location, instead of having to do the same thing on a per-repository basis. I hope you find this information useful. Do feel free to hit me up--on the Fediverse, on Twitter, or in any of a variety of Slack communities--if you have any questions or any feedback! Metadata and Navigation Git CLI Previous Post: Automatically Transforming Git URLs Next Post: Dynamically Enabling the Azure CLI with Direnv Be social and share this post! Related Posts * Automatically Transforming Git URLs 11 Dec 2023 * Technology Short Take 157 22 Jul 2022 * Git Difftool and Meld as a Flatpak 27 May 2022