Getting the GitHub Verified commit badge when using Visual Code on Mac OS X
Tags: general, code, commit, github
Published: 2021-05-05 19:05:00

---
title: Getting the GitHub Verified commit badge when using Visual Code on Mac OS X
published: true
date: 2021-05-05 14:05:07 UTC
tags: General,code,commit,github
canonical_url: https://veducate.co.uk/github-verified-code/?utm_source=rss&utm_medium=rss&utm_campaign=github-verified-code
---

###### The Issue

Recently I’ve started to use Visual Code as my editor on Mac OS X, and [using it with my GitHub Repos](https://code.visualstudio.com/docs/editor/github). It’s pretty cool! However I noticed that when I submit a commit via code, I do not see the verified badge.

[![github commit view - verified](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Verified-Commit.jpg?resize=604%2C169&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Verified-Commit.jpg?ssl=1)

###### The Cause

When I look at my global git config on my Mac OS X machine, I can see that I’ve configured the settings so that my user details are passed to GitHub as an author of the repository.

```
git config --global --list
```

[![git config --global --list](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/git-config-global-list.jpg?resize=408%2C81&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/git-config-global-list.jpg?ssl=1)

###### The Fix

We need to setup a GPG public key to be used by git on our machine when interacting with GitHub.

- First we need to [install GPG](https://www.gnupg.org/download/), if you do not have it already, it is not installed on Mac OS X by default.
- Secondly in my GitHub account, I want to get my no-reply email address as I have [email privacy turned on](https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address). Meaning my personal email will not be exposed in commits.
  - Go to settings > emails > find your ” no reply email under the “primary email address” header

```
Note: If you are happy to expose your email address used with GitHub, then just use your actual email address in the relevant sections.
```

[![GitHub emails - primary email address - no reply email address](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-emails-primary-email-address-no-reply-email-address.jpg?resize=604%2C305&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-emails-primary-email-address-no-reply-email-address.jpg?ssl=1)

Open up terminal on your Mac OS X machine and run the following command and provide the details as necessary;

```
gpg --full-generate-key
```

- Select “RSA and RSA (default)”
- Set your key size to 4096
- Set your expiry
- Add your Real User Name logged with GitHub
- Enter your no-reply email.
- Set a comment about the GPG key if you need to.
- Enter a passphrase in the dialog box that appears

[![gpg --full-generate-key](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/gpg-full-generate-key.jpg?resize=604%2C505&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/gpg-full-generate-key.jpg?ssl=1)

[![gpg generate new key - provide passphrase - pinentry mac](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/gpg-generate-new-key-provide-passphrase-pinentry-mac.jpg?resize=545%2C263&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/gpg-generate-new-key-provide-passphrase-pinentry-mac.jpg?ssl=1)

You can now view your key details by running the following and get your Key ID in this example below, the Key ID is “3AA5C34371567BD2”:

```
$ gpg --list-secret-keys --keyid-format LONG
/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid Hubot <hubot@example class="com">
ssb 4096R/42B317FD4BA89E7A 2016-03-10</hubot@example>

```

Now we need GPG ID in ASCII Amour Format:

```
gpg --armor --export {Key_ID}
```

Copy your GPG key,

```
Beginning with:

-----BEGIN PGP PUBLIC KEY BLOCK-----

And ending with:

-----END PGP PUBLIC KEY BLOCK-----
```

[![gpg --armor --export](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/gpg-armor-export.jpg?resize=463%2C185&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/gpg-armor-export.jpg?ssl=1)

And we’ll now add this to our GitHub account.

- Go to Settings > SSH and GPG Keys > New GPG Key
- Paste in your PGP output and save. Confirm your password
- You will now see your key has been added

[![GitHub - SSH and GPG Keys - New GPG Key](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-SSH-and-GPG-Keys-New-GPG-Key.jpg?resize=604%2C326&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-SSH-and-GPG-Keys-New-GPG-Key.jpg?ssl=1) [![GitHub - SSH and GPG Keys - New GPG Key - Add New](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-SSH-and-GPG-Keys-New-GPG-Key-Add-New.jpg?resize=604%2C278&ssl=1)](https://i2.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-SSH-and-GPG-Keys-New-GPG-Key-Add-New.jpg?ssl=1) [![GitHub - SSH and GPG Keys - New GPG Key - Key Added](https://i1.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-SSH-and-GPG-Keys-New-GPG-Key-Key-Added.jpg?resize=604%2C298&ssl=1)](https://i1.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-SSH-and-GPG-Keys-New-GPG-Key-Key-Added.jpg?ssl=1)

Now we all have to tell Git to use our GPG key for signing those commits when they are pushed by our system and Visual Code.

Within terminal using the key ID we found earlier:

```
# Reminder on how to get your Key ID
gpg --list-secret-keys --keyid-format LONG

# Configure git to use the Key ID and sign our commits

git config --global user.signingkey {Key_ID}
git config --global commit.gpgsign true
```

Let’s now test this. I’ve made a change to a file in a repo, and I’ve staged the commit. Which now triggers me to provide my GPG passphrase. I will select to save it in Apple Keychain so I don’t have to keep re-entering it.

And one I push the commit, I can see I am now verified on GitHub again.

[![Visual Code - Commit staged changes - provide passkey](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Visual-Code-Commit-staged-changes-provide-passkey.jpg?resize=604%2C285&ssl=1)](https://i0.wp.com/veducate.co.uk/wp-content/uploads/2021/05/Visual-Code-Commit-staged-changes-provide-passkey.jpg?ssl=1) [![GitHub - Verified commit from Visual Code](https://i1.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-Verified-commit-from-Visual-Code.jpg?resize=604%2C85&ssl=1)](https://i1.wp.com/veducate.co.uk/wp-content/uploads/2021/05/GitHub-Verified-commit-from-Visual-Code.jpg?ssl=1)

###### Resources

- GitHub Docs – [Managing commit signature verification](https://docs.github.com/en/github/authenticating-to-github/managing-commit-signature-verification)
- [Getting Verified badge next to your GitHub commits in VS Code on Microsoft Windows](https://evotec.xyz/getting-verified-badge-next-to-your-github-commits-in-vs-code/)

Regards

[Follow @Saintdle](https://twitter.com/saintdle)<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

[Dean Lewis](https://uk.linkedin.com/in/saintdle?trk=profile-badge)

The post [Getting the GitHub Verified commit badge when using Visual Code on Mac OS X](https://veducate.co.uk/github-verified-code/) appeared first on [vEducate.co.uk](https://veducate.co.uk).