Skip to content

Instantly share code, notes, and snippets.

@saradindusengupta
Last active October 18, 2022 12:51
Show Gist options
  • Save saradindusengupta/5396f27fd98ab43a58514b1d1f6e8ee5 to your computer and use it in GitHub Desktop.
Save saradindusengupta/5396f27fd98ab43a58514b1d1f6e8ee5 to your computer and use it in GitHub Desktop.
Git Repository-wise configuration Guide for verified signed commit with GPG in GitHub

Git Repository-wise configuration Guide for verified signed commit with GPG in GitHub

1. Generate GPG keys

  1. Download and install the GPG command line tools for your operating system. We generally recommend installing the latest version for your operating system.
  2. Open Git Bash.
  3. Generate a GPG key pair. If you are not on version 2.1.17 or greater then
    1. gpg --default-new-key-algo rsa4096 --gen-key
  4. Enter your user ID information.
  5. Type a secure passphrase. This is a must.
  6. list the long form of the GPG keys
    1. gpg --list-secret-keys --keyid-format=long
  7. From the list of GPG keys, copy the long form of the GPG key ID you'd like to use. In this example, the GPG key ID is 6516ETRY5D63A374
    1. gpg --list-secret-keys --keyid-format=long
sec rsa4096/6516ETRY5D63A374 2022-04-20 [SC] [expires: 2024-04-19]
728B31B9A433BF3KOY549042651642177D63A374
uid [ultimate] username <youremail@example.com>
  1. Paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is 6516ETRY5D63A374
    1. gpg --armor --export 6516ETRY5D63A374
  2. Copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK-----.
  3. Adding a new GPG key to GitHub

2. List all the GPG keys in the system

gpg --list-secret-keys --keyid-format=long

3. Copy the second part of the sec after /

The below mentioned key id is dummy for understanding purposes.

sec rsa4096/6516ETRY5D63A374 2022-04-20 [SC] [expires: 2024-04-19]
728B31B9A433BF3KOY549042651642177D63A374
uid [ultimate] username <youremail@example.com>

Here only copy 6516ETRY5D63A374

4. Configure GPG Signing key

  1. cd ~/to_the_repository_directory
  2. git config user.signingKey <copied key id in earlier step>
  3. git config user.email <your email id>

Current Git Global Settings

git config --global user.signingKey 651642177D63A374 git config --global user.email youremail@example.com

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