Git setup for multiple organisations
Dynamically use different Git Email
How many times have you accidentally committed something with a gmail address to a customer repository?
I wanted to get my commit messages sorted once and not need to worry about it again, so I set out trawling the inter-webs.
My requirement
The local repo structure I have is something like:
I wanted all repositories within the "Github Organisation / User" to be have specific settings like `git.email` and signing to be specific to that section
The solution
Setting up a base .gitconfig and then conditional email based on the folder of the repository.
[gpg "ssh"]
program = /Applications/1Password.app/Contents/MacOS/op-ssh-sign
[gpg]
format = ssh
[commit]
gpgsign = true
[user]
name = Richard Keit
[includeIf "gitdir:~/git/personal/"]
path = .gitconfig-personal
[includeIf "gitdir:~/git/work/clientA/"]
path = .gitconfig-client-a
[user]
email = richard@keit.dev
signingkey = ssh-ed25519 AA..
In action
As I use 1Password both professional and personally, I opted to config new SSH keys for signing and authentication to Github - as we can see from the "gpg 'ssh'" section of my `.gitconfig` file.
1Password allows for biometric unlocking, which means the SSH keys are never persisted on disk - which is a great win. Make sure to upgrade to the latest version of the 1Password CLI if this is not working
As we can see on Github, my commit has been signed successfully.
1Password also has the same write up here which is was very helpful, when I found it afterwards