Skip to content

Instantly share code, notes, and snippets.

@matthewjberger
Last active March 20, 2023 05:37
Embed
What would you like to do?
Setting up GPG with git for signed commits
# Generate a key
# RSA and RSA
# 4096 bits
# Email from your .gitconfig
gpg --full-generate-key

# List key information
gpg --keyid-format LONG -k

# Make sure the email from your gitconfig is attached to the key
# and shows up when listing key information.

# Add more email addresses to your gpg key if desired
# This must be done before uploading the key
gpg --edit-key the_key_id
gpg> adduid
# ... enter name and email information
gpg> save

# Use the gh client to upload the key
gh auth refresh -s write:gpg_key
gpg --armor --export the_id | gh gpg-key add -

# Configure git to use our gpg key when signing commits
git config --global user.signingkey the_key_id

# Enable gpg signing for commits
git config --global commit.gpgsign true

# On windows you may need some additional settings.

# Point git to the correct GPG path. Update the path here to wherever your gpg program is located
git config --global gpg.program "C:\Users\matth\scoop\apps\gpg\current\bin\gpg.exe"

# Ensure the gpg agent is running
gpg-connect-agent reloadagent /bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment