Skip to content

Instantly share code, notes, and snippets.

@sfgeorge
Created June 4, 2023 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfgeorge/5191b0c9925a7b4f977db9482705d4f7 to your computer and use it in GitHub Desktop.
Save sfgeorge/5191b0c9925a7b4f977db9482705d4f7 to your computer and use it in GitHub Desktop.
How to GPG-sign git commits on GitHub, the easy way

How to GPG-sign git commits on GitHub, the easy way

  1. πŸ“‹ Copy your GitHub email address.

    Run git config --global user.email and copy the email that is returned. If nothing is returned, you should set that to one of the following 2 addresses on https://github.com/settings/emails :

    i. If you have enabled βœ… Keep my email addresses private, then copy the xxxxx+xxxxx@users.noreply.github.com email address mentioned beneath.
    ii. Otherwise, copy the email address that you have designated under Primary email address.

  2. πŸ“¦ Install GPG

    For ease of use with GPG key creation and management, you can install GPG Suite from https://gpgtools.org/
    There is an add-on Email integration that installation will ask if you would like installed. This is optional / not needed for git-GPG signing purposes.

  3. πŸ”‘πŸ”‘ Create a new GPG key pair

    Launch the GPG Keychain app and click + New.
    Important: Use the email address that you copied from Step 1. above.

  4. πŸ—ƒοΈ Follow the Telling Git about your GPG key instructions on
    https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key#telling-git-about-your-gpg-key
    πŸ›‘ Stop when you reach the next section, titled Telling Git about your SSH key.

  5. πŸ™ Finish on GitHub

    Follow the Adding a GPG key to your GitHub account instructions on
    https://docs.github.com/en/authentication/managing-commit-signature-verification/adding-a-gpg-key-to-your-github-account

Now to test it out!

  1. Commit

    Make a test commit in a new or existing git repo
    git commit -S --allow-empty -m 'My 1st signed commit'

  2. Verify locally

    Check to confirm that local git acknowledges that the commit was signed and valid.
    git log --show-signature

  3. Push and verify on GitHub

    https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment