Git supports conditional includes since version 2.13. With these you're able to allow overrides under specific conditions. Sometimes it's useful to separate configurations, because your company uses different git settings like email or ssh key.
I've organised my projects in different directories, private and work.
~/
├── private
└── work
I add a config file in my work directory, which will override my global git settings, with my work settings.
# ~/projects/work/.gitconfig
[user]
email = marian.gaebler@protofy.com
[core]
sshCommand = "ssh -i /Users/mariangaebler/.ssh/protofy_rsa"
Go to your global git config and add the following line ~/.gitconfig
.
...
[includeIf "gitdir:~/projects/work/**"]
path = /Users/mariangaebler/projects/work/.gitconfig
Finaly you have to initialize git in your work-folder.
git init
And we're done.
You can test your settings with git config -l
or git config user.email
. The correct value should be outputted.