For access : you can use your ~/.ssh/config
file to set different keys for different servers.
# in your ~/.ssh/config file :
Host github.com
IdentityFile path/to/github_key
Host gitlab.com
IdentityFile path/to/gitlab_key
Once set up, any ssh interaction with github.com
(resp. gitlab.com
) -- e.g : git clone git@github.com:repo
, git fetch
, git push
... -- will use github_key
(resp. gitlab_key
) by default.
For git
config parameters (e.g : user.name
and user.email
), you can use includeIf
sections (link to docs) as suggested by @choroba :
# in your .gitconfig file :
[includeIf "gitdir:~/github/**"]
path = ~/path/to/github_conf_file
[includeIf "gitdir:~/gitlab/**"]
path = ~/path/to/gitlab_conf_file
and set the user.name
and user.email
values in github_conf_file
and gitlab_conf_file
.