Platform-Specific .gitconfig’s and the Wonderful includeIf

Mike Mackintosh
Doing Things Right

--

By now, you’ve invested plenty of time in your local configurations to make yourself as productive as possible. It’s not uncommon for engineers, admins and power users to spend a lot of time in many different contexts, such as a linux server somewhere in the ether, your macOS laptop for work, or even a Windows gaming rig at home.

It’s common for configurations to be stored on https://github.com under what’s known asDotfiles. You can learn more about ~/.gitconfig’s looking at the manpage’s forgit-config. This configuration file allows you to define how you want to interact with git such as how to view diff’s, your author information like name and email, your gpg key for signing and much, much more.

One thing that is only lightly touched upon in the documentation is the use of the includeIf statements. It is a conditional include for additional configuration’s. What is not commonly shared about this feature is the ability for you to define the different path prefixes, and set configurations accordingly. Since each operating system uses their own user directory path, we have an easy way to identify which platform git is running on.

The configuration block you would add is as follows:

[includeIf "gitdir:/Users"]
path = ~/.gitconfig-macos

--

--

Mike Mackintosh
Doing Things Right

#infosec professional, #corpsec thought leader, #golang dev, master blaster of #devops — ex-@snap, ex-@signalsciences, ex-@shutterstock, ex-@vzw