Introduction
I often need different Git settings depending on the repository I'm working on, and I want to version and centralize those settings in my dotfiles repo. This blog post outlines a structure for checking out our repository and using the Git feature `includeIf` to load different settings by folder, while storing all those settings in my dotfiles repo.
Repo checkout structure
A git repo is self-contained in a directory. If you want to move the repositories to match the outline I am about to describe, simply move the folder.
Similar to the Java package naming structure, I check out the git repositories starting from the broadest category and then, for each folder, get more specific. I start with a folder called repo and notice that it's lowercase. Then I have one folder for each hosting provider, e.g.:
- gitlab
- github
Followed up with any potential customer, for example:
- repo/gitlab/{customer-a}/{subdomain-x}/{application}
I try to use a subdomain that maps to a system, following my https://fredrkl.com/blog/service-oriented-architecture-framework/, plus the application name for the repo.
Git config
In my dotfiles repo, I keep a .gitconfig file and create a symbolic link to:
ln -sf ~/dotfiles/.gitconfig ~/.gitconfig.
Now this gitconfig references other gitconfig files that are enabled for specific paths, using the pretty neat git feature includeIf:
...
[includeIf "gitdir:~/repos/github/customer1/"]
path = ~/.gitconfig-cust1
[includeIf "gitdir:~/repos/azure-devops/customer2/"]
path = ~/.gitconfig-customer2-azure-devops
...
Customer 1 gitconfig
[user]
name = Fredrik Klingenberg.
email = fredrik.klingenberg.E@customer1.XY
signingkey = SIGNINGKEY
Customer 2 gitconfig
[user]
name = Fredrik Klingenberg.
email = fredrik.klingenberg.E@customer2.XY
[core]
sshCommand = ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes
This was particularly useful since Azure DevOps repositories only support checking out repositories using SSH with RSA and not my default ed25519.