I have 1 github user and another gitlab user, and I have created 1 gpg key for each because my email address differs.
The problem is I have to execute git config --global user.signingkey everytime I want to commit to different git repos.
Is there a way I can manage my gpg keys per git user?
I have the same situation but with splitting of work/personal accounts. And I have a lot of repositories but I don't want to run
git configevery time I clone something new.I have written a blog post about it. A way to do this automatically is to use the
includeIfdirective provided by git. You can read more about it from the Conditional Include section in git manual.There's a small requirement tho, you need to be able to tell apart github repositories from your GitLab repositories by a component in your path (for example, put GitHub clones in
~/githuband Gitlab clones in~/gitlab)Then, basically, split the signing key configuration into two files:
And then in your main
~/.config/git/configconfiguration file, use theincludeIf gitdir:directive to match and include different files based on your WD:Then all repos in your
~/githubfolder will automatically use your GitHub key and repos in your~/gitlabfolder will use your GitLab keys.