Skip to content
$ gitswitch
Nord
★ star

GPG Signing

gitswitch automatically switches your GPG signing key when you change identities.

Terminal window
gitswitch work
# Now commits signed with gpg are signed by your work key

If you sign commits with GPG (commit signing is recommended for security), each identity might use a different key:

  • Work identity signs with your corporate GPG key
  • Personal identity signs with your personal GPG key
  • Different keys may be registered with different GitHub accounts

Forgetting to update the signing key means:

  • Unsigned commits attributed to the wrong identity
  • Verification failures
  • Trust issues on public repos

gitswitch handles it automatically.

Terminal window
gitswitch add work "Alice" alice@company.com \
--gpg-key 1234567890ABCDEF

The GPG key ID should match a key in your keyring:

Terminal window
# List your GPG keys
gpg --list-secret-keys --keyid-format LONG
# Output:
# sec rsa4096/1234567890ABCDEF 2023-01-15 [SC]
# 1234567890ABCDEF1234567890ABCDEF12345678

Use the 16-character ID after the /.

Terminal window
gpg --gen-key
# Follow the prompts to create a new key
gpg --list-secret-keys --keyid-format LONG
# Find your new key ID

When you switch profiles with a GPG key, gitswitch sets:

Terminal window
git config --global user.signingkey KEYID

Git looks up this key in your keyring when signing commits.

After switching to a profile with a GPG key, sign commits:

Terminal window
git commit -S -m "Signed commit"

Or configure git to always sign:

Terminal window
git config --global commit.gpgsign true

Now every commit is signed automatically.

Check which key signed a commit:

Terminal window
git verify-commit COMMIT_SHA

Or see in log:

Terminal window
git log --show-signature

Setup multiple profiles with different keys:

Terminal window
# List your keys
gpg --list-secret-keys --keyid-format LONG
# Add profiles
gitswitch add personal "Alice" alice@gmail.com \
--gpg-key PERSONAL_KEY_ID
gitswitch add work "Alice" alice@company.com \
--gpg-key WORK_KEY_ID

When you switch, the signing key switches too.

error: key "KEYID" does not contain a secret key

Check:

  1. Is the key ID correct?
  2. Is the key in your keyring?
Terminal window
# List available keys
gpg --list-secret-keys --keyid-format LONG
# Add to keyring if needed
gpg --import ~/path/to/key.gpg

If GPG hangs or asks for passphrase every time:

  1. Use gpg-agent to cache passphrases:
Terminal window
# Edit ~/.gnupg/gpg-agent.conf
default-cache-ttl 3600
max-cache-ttl 7200
  1. Restart gpg-agent:
Terminal window
gpgconf --kill gpg-agent

GitHub only recognizes GPG keys that are:

  1. Added to your GitHub account
  2. Email-associated with a GitHub account

Check:

  1. Go to https://github.com/settings/keys
  2. Verify your GPG key is listed
  3. Verify the email matches your git config

If you set a per-repo signing key:

Terminal window
cd ~/special-repo
git config --local user.signingkey SPECIAL_KEY_ID

Local config takes priority over global.

GitHub Account Sync
Identity Awareness
SSH Key Management