Skip to content

Instantly share code, notes, and snippets.

@DMeechan
Created June 12, 2019 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DMeechan/117cf677a2c975cb9f0aebaf7a96bcdc to your computer and use it in GitHub Desktop.
Save DMeechan/117cf677a2c975cb9f0aebaf7a96bcdc to your computer and use it in GitHub Desktop.
Using GPG

Prerequisites (Mac)

  • brew install gnupg

Setting up GitHub / GitLab

  1. Check public key ID: gpg --list-secret-keys --keyid-format LONG
  2. Then where it says sec rsa4096/KEY_ID, take the KEY_ID and put it into the command below:
  3. Copy public key: gpg --armor --export KEY_ID | pbcopy
  4. Open up GitHub (or GitLab): open https://github.com/settings/keys

Importing the secret key to a new machine

  1. Get the .asc file
  2. gpg --import my-private-key.asc

Then follow the Git instructions below...

Setting up Git

  1. Get the KEY_ID from gpg --list-secret-keys --keyid-format LONG (explained above)
  2. git config --global user.signingkey KEY_ID
  3. Do git config --global commit.gpgsign true... or do everything manually by adding the -S flag to every commit to sign it
  4. If you get an error about failed to write commit object, you need to export the GPG TTY in Terminal or PATH: export GPG_TTY=$(tty). If you use Fish, add this to your config.fish file: set -x GPG_TTY (tty)

Creating an unsigned commit

git -c commit.gpgsign=false commit -m "MESSAGE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment