Sections

Generating GPG Key

generate gpg key

$ gpg --full-generate-key

generate gpg key

$ gpg --list-secret-keys --keyid-format LONG

Adding The GPG Key to Github Account

From the list of GPG keys, copy the GPG key ID you’d like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

$ gpg --list-secret-keys --keyid-format LONG
/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid                          Hubot 
ssb   4096R/42B317FD4BA89E7A 2016-03-10

Paste the text below, substituting in the GPG key ID you’d like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

$ gpg --armor --export 3AA5C34371567BD2
# Prints the GPG key ID, in ASCII armor format

Copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK-----

Add the GPG key to your GitHub account

Signing Git Commits

for macOS users, follow https://stackoverflow.com/questions/39494631/gpg-failed-to-sign-the-data-fatal-failed-to-write-commit-object-git-2-10-0

To set your GPG signing key in Git, paste the text below, substituting in the GPG key ID you’d like to use. In this example, the GPG key ID is 3AA5C34371567BD2

$ git config --global user.signingkey 3AA5C34371567BD2

When committing changes in your local branch, add the -S flag to the git commit command:

$ git commit -S -m your commit message
# Creates a signed commit

To configure your Git client to sign commits by default for a local repository, in Git versions 2.0.0 and above, run:

git config commit.gpgsign true

To sign all commits by default in any local repository on your computer, run:

git config --global commit.gpgsign true