Programming-Server.com - Different Git Configs per Folder
How to use includeIf in your gitconfig to switch identities based on the workspace folder.
Git TrainingDifferent Configurations for Git depending on the Workspace Folder
Sometimes you want to use different emails or GPG keys for your git projects (e.g., separating work and private projects). For this, you can use the includeIf directive in your .gitconfig.
Implementation
If all your projects are under ~/workspace but you want specific settings for ~/workspace/acme/*, use this setup:
File: ~/.gitconfig
[user]
email = [email protected]
name = Mike
signingkey = 123ABCDEF456
[includeIf "gitdir:~/workspace/acme/"]
path = .gitconfig-acme
File: ~/.gitconfig-acme
[user]
email = [email protected]
name = Mike Petersen
signingkey = 789ABCDEF456
[commit]
gpgsign = true