In the previous PGP article, I showed what PGP is, what it is for, and how to create your own key on Manjaro (and on Linux Kamarada). One of the most practical uses of a PGP key is signing your commits on Git, proving that it was really you who made them. In this article, I’ll show you how to add your key to GitHub and GitLab and configure Git to sign your commits automatically.
Why sign your commits
As I explained in the previous article, anyone can make a commit using your name and email – Git doesn’t verify that it was really you. By signing your commits with your PGP key, you cryptographically prove that you were the author. Platforms such as GitHub and GitLab recognize that signature and show a Verified badge next to the commit, as I showed in the image in the previous article.
Requirements
To follow this tutorial, you need:
- a PGP key already created (see how to do that in the previous article); and
- Git installed and configured with the same name and email you used for your PGP key.
To check the name and email configured in Git, run:
1
2
$ git config --global user.name
$ git config --global user.email
If the email shown is different from the one you used to create your key, adjust one of the two (either Git’s or the key’s) so they match – that’s the email GitHub and GitLab will use to check whether the signature corresponds to your key.
How to export your public key
First, you need to export your public key in the format GitHub and GitLab expect (ASCII armor). Run (replace the email with the one you used when creating the key):
1
$ gpg --armor --export contato@viniciusmenezes.dev
The output should look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEawJXWxYJKwYBBAHaRw8BAQdAvUrOMgC22nj5IdBPqXSX1SuWmcM0zVISmTkH
IDmAkQe0LlZpbmljaXVzIE1lbmV6ZXMgPGNvbnRhdG9AdmluaWNpdXNtZW5lemVz
LmRldj6IlgQTFgoAPhYhBKkU3rugZWF5pbMd2/oSUixAEawoBQJrAldbAhsDBQkD
wmcABQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJEPoSUixAEawo7vcA/j0p6iSL
1r/trfbELOIZ/CYGuz23/RhVZGmO6n60cCQUAQCcyl/eS6JrpeEkxl/PxxzFH271
2a1FGtp5oy7Qw280DLg4BGsCV1sSCisGAQQBl1UBBQEBB0DBafpxBAXAKUEoPn5Q
OHwuTht50NKVng+w2d7HyKReCAMBCAeIfgQYFgoAJhYhBKkU3rugZWF5pbMd2/oS
UixAEawoBQJrAldbAhsMBQkDwmcAAAoJEPoSUixAEawosBUBANsSQMbS+fQ5HuRC
d2WTyx9Aj79TFTho8gvbXklDp0uAAPwLUY4y3c6oXw51IG26rHNwtqEisYFWhuqI
+5nrMM/pAA==
=3XJd
-----END PGP PUBLIC KEY BLOCK-----
Copy the whole block, from -----BEGIN PGP PUBLIC KEY BLOCK----- to -----END PGP PUBLIC KEY BLOCK-----, including those two lines. You’ll paste that text into GitHub and/or GitLab.
How to add the key to GitHub
On GitHub, go to your account Settings:
In the side menu, click SSH and GPG keys. Then, click the New GPG key button:
Paste the public key block you copied and click Add GPG key:
GitHub may ask for your password or two-factor confirmation before it finishes.
Done! Your key now shows up listed among the GPG keys on your account:
How to add the key to GitLab
On GitLab, go to your Preferences:
In the side menu, go to Access > GPG keys. Then, click the Add new key button:
Paste the public key block you copied into the Key field and click Add key:
Done! Your key now shows up listed among the GPG keys on your account:
Just like GitHub, GitLab will only mark a commit as verified if the email used in it matches a verified email on your account and the identity (uid) present in your PGP key.
How to configure Git to sign your commits
First, find your key’s identifier (key ID):
1
$ gpg --list-secret-keys --keyid-format=long
The output should look something like this, where what matters is what comes after ed25519/ (or the entire fingerprint, which also works):
1
2
3
4
sec ed25519/FA12522C4011AC28 2026-11-22 [SC] [expires: 2028-11-21]
A914DEBBA0656179A5B31DDBFA12522C4011AC28
uid [ultimate] Vinicius Menezes <contato@viniciusmenezes.dev>
ssb cv25519/93E5D82DB7454CC8 2026-11-22 [E] [expires: 2028-11-21]
Now, tell Git which key to use and turn on automatic commit signing:
1
2
$ git config --global user.signingkey A914DEBBA0656179A5B31DDBFA12522C4011AC28
$ git config --global commit.gpgsign true
If you’d rather sign commits only in a specific repository instead of all of them, replace --global with --local and run the command from inside that repository.
You can also sign Git tags with your key by adding the -s option to git tag. For instance:
1
$ git tag -s v1.0 -m "version 1.0"
Testing the signature
Inside any Git repository, make a test commit:
1
$ git commit --allow-empty -m "test signed commit"
Since you turned on commit.gpgsign, Git will ask for your key’s passphrase (or use the one already cached in memory by gpg-agent) and sign the commit automatically. To check whether the signature is correct, run:
1
$ git log --show-signature -1
The output should show that the signature is good (Good signature from):
1
2
3
4
5
6
7
8
commit af0516b6e00d532db4654268ebd03720ca61489e (HEAD -> master)
gpg: Signature made Sun 22 Nov 2026 09:04:36 AM -03
gpg: using EDDSA key A914DEBBA0656179A5B31DDBFA12522C4011AC28
gpg: Good signature from "Vinicius Menezes <contato@viniciusmenezes.dev>" [ultimate]
Author: Vinicius Menezes <contato@viniciusmenezes.dev>
Date: Sun Nov 22 09:04:36 2026 -0300
test signed commit
If you want to sign a specific commit without having turned on automatic signing, use the -S (capital S) option of git commit:
1
$ git commit -S -m "test signed commit"
Checking the “Verified” badge
Push the commit to GitHub or GitLab and open the repository page. Next to the commit, you should see the Verified badge:
Troubleshooting common issues
-
“gpg failed to sign the data” or no passphrase prompt shows up: in many cases, this happens because gpg-agent doesn’t know which terminal it should show the passphrase prompt on. Add this line to your
~/.bashrc(or your shell’s equivalent file) and open a new terminal:1
export GPG_TTY=$(tty)
-
Git can’t find the right gpg program: on some distributions, the command is called gpg2. If that’s your case, explicitly configure which program to use:
1
$ git config --global gpg.program gpg2
-
the “Verified” badge doesn’t show up even though the commit is signed: check whether the commit author’s email (the same one shown by
git config --global user.email) exactly matches the email present in your PGP key’s identity (uid), and whether that email is registered and verified on your GitHub or GitLab account.