Sign Github commits using dynamic signingkey

175 Views Asked by At

I have a Github account linked with 2 email addresses, (Personal + work). I'm only able to sign commits coming from one account, using git config --global user.signingkey MySigningKey because the key is associated with one email.

I'm using direnv to commit using different emails depending on the directory that I'm in, it works setting an .envrc with an enviroment variable like export [email protected]. I was wondering if there was a similar solution to define dynamic signing keys

1

There are 1 best solutions below

0
On

Note: if your email is stored in the local configuration of a Git repository (with git config user.email), your commit will use the right email when you need to sign commits.
Meaning you would not need direnv.

In order to avoid the global setting to interfere with repositories using the other email, you could:

  • either declare user.signingkey only in the repositories using the correct user.email.
  • or define on your machine a separate user account for working on those repositories (meaning you can keep the user.signingkey option global for that separate account)