Install gpg via Homebrew.
brew install gnupg
Here you can generate keys yourself or import an existing key.
gpg --generate-key // OR gpg --import path/to/secret.asc
Now we tell git what key we want to use. Run this command to list your keys:
gpg --list-secret-keys --keyid-format=long
You should see some output like below, copy the highlighted section:
sec rsa2048/9A9A9A9A9A9A9A9A 2015-05-01 [SC]
Then set it as user.signingkey in git config
git config --global user.signingkey 9A9A9A9A9A9A9A9A
Tell git to sign commits and which program to use
git config --global commit.gpgsign true git config --global gpg.program gpg
In your bash profile set the following to allow for passphrase entry:
Alternatively you can use the pinentry tool from homebrew.
Thats it! From now on, any new commits will be automatically signed. The program might ask you for your passphrase through your mechanism of choice (terminal/pop up etc).
How to retroactively sign all commits in a branch – ManthanHD
[…] If you haven’t set up GPG signing, check out my previous post on this here. […]