Skip to content

How do I pass –homedir to git when signing using GPG?

I have a custom location where I have my GPG keys, which is different from the default ~/.gnupg directory.

I need to sign a git commit using GPG, but I can’t find any option to specify the custom location to Git: it always searches in the default one.

Is there an option for this? I tried modifying:

program = /usr/bin/gpg --homedir ~/.mygnupg in the .git/config file but no luck!



You should be able to use the GNUPGHOME environment variable:

GNUPGHOME=~/.mygnupg git commit ...

You can also set this variable in your ~/.profile or ~/.bash_profile if you want it to always be set to that value.

User contributions licensed under: CC BY-SA
8 People found this is helpful