I recently added my GPG key to my git in order to sign commits. While doing so I ran into big problem. SourceTree wouldn’t allow me to configure it to use my HomeBrew GPG installation (Error message: Invalid GPG Path). By default SourceTree only works with the GPG Suite under MacOS, which is quite annoying since HomeBrew is pretty much my go-to approach to install anything command line related, as it should be for everyone 😉
In order to get SourceTree working with GPG (GNUPG) under Mac you need to do the following.
1. First install all GPG HomeBrew packages and Pinentry for Mac
$ brew install gpg-agent gpg2 libgpg-error pinentry-mac
2. If you haven’t already generated your GPG key:
$ gpg --gen-key
$ gpg --gen-key ... pub rsa2048 2018-06-28 [SC] [expires: 2020-06-22] 0A46826A uid Kevin Goedecke <email@example.com> sub rsa2048 2018-06-22 [E] [expires: 2020-06-22]
Now tell you git cli to sign your commits with the key, that you just generated (replace the key ID with the key from the previous step).
$ git config --global user.signingkey 0A46826A
After you’ve done this open SourceTree and then the settings (CMD + ,) and click on the “Advanced” tab on the right.
Click on Browse and navigate to /usr/local/bin , homebrew created already a symlink to ../Cellar/gnupg/2.2.8/bin/gpg here. Usually we would like to point SourceTree to this path and that’s it. But wait if we select this directory and try to close the settings. We get this:
Annoying… but there’s a little workaround. We will create a symlink to make SourceTree think there a file called gpg2 . So let’s just do that:
$ ln -s ../Cellar/gnupg/2.2.8/bin/gpg /usr/local/bin/gpg2
Afterwards you can simply select the directory in SourceTree and it will accept it as your GPG binary.