GPG Key in Git - Get Your Every Commit Verified
This article is based on the contents of the Github’s documentation.
You will get your own verified badge on every git commits once you configure your GPG key with your VCS.
First things first, check your gpg version using this command:
|
|
Allow me to assume that you are on version 2.1.17 or greater.
Use this command to generate a GPG key:
|
|
Choose the default for kind of key and give 4096 for key size, choose 0
for expiration time or up to your decision otherwise.
Enter your git ID(or full name is also fine), email which is verified in your git account already.
Set your password for the GPG key.
After you confirm your configurations, do some memory-consuming operations(for example, looping through a million-sized simple array in python or ruby) so that the key generation process wouldn’t take too long.
Now that the key generation process has been finished, use this command to list all your GPG keys in your machine.
|
|
You should see results looking like this:
In the above example, C82530CF298B7FD4 is your GPG key ID.
Use this command to retrieve your GPG key:
Copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK-----
and ending with -----END PGP PUBLIC KEY BLOCK-----
.
Paste it into the GPG keys field in your git account settings.
Well, so far so good.
Now, use this commands to tell your git to sign every commits with GPG key to get verified.
The second line will force you to sign every commits on your machine.
If you do not like it for some reason, skip the line and use -S tag instead, whenever you commit with signature.
|
|
Finally, add this line to your .bashrc
or to any other of your auto-loaded dot files like .bash_profile
, .profile
.
|
|
If you want to remove your GPG key from your machine:
If you want to backup your key pair as files:
If you want to import your backuped key pair:
Hooray! You did it!
Happy coding! 😎