|
| 1 | +Setting up GPG for Git |
| 2 | +====================== |
| 3 | + |
| 4 | +If you want to use the GPG feature within `git`, there are a few steps for you to follow. These steps are described at many places, but a reminder never hurts. |
| 5 | + |
| 6 | +Generating a new key |
| 7 | +-------------------- |
| 8 | + |
| 9 | +If you don't have any GPG key yet, you can generate it from a terminal (or Git Bash for Windows) using the following command: |
| 10 | + |
| 11 | + $ gpg --gen-key |
| 12 | + |
| 13 | +Follow the wizard and answer the questions about your identity (name, email address). It's advised to leave the default values, but if you wish extra security, chose a keysize of 4096. |
| 14 | +Once generated, you can export your keys via the following commands: |
| 15 | + |
| 16 | + $ gpg --export --armor user@example.com > public.asc |
| 17 | + $ gpg --export-secret-keys -o private.gpg user@example.com |
| 18 | + $ gpg --output revokecert.asc --gen-revoke user@example.com |
| 19 | + |
| 20 | +This will output three different files: |
| 21 | + |
| 22 | +* `public.asc` contains your public key. Copy its content and [send it to GitHub](https://help.github.com/articles/adding-a-new-gpg-key-to-your-github-account/) or any other git service you use |
| 23 | +* `private.gpg` contains your private key. This one needs to be put on a safe place. You must **avoid publishing somewhere at all cost** |
| 24 | +* `revokecert.asc` contains a certification for revoking your keys. Simply put, you'll need it only if your keys gets compromised |
| 25 | + |
| 26 | +Importing an existing key |
| 27 | +------------------------- |
| 28 | + |
| 29 | +If you already have a GPG key that you wish to use for signing your commits, you must first import it to your system (if it's not present). |
| 30 | + |
| 31 | +Check which keys you already have: |
| 32 | + |
| 33 | + $ gpg --list-secret-keys |
| 34 | + |
| 35 | +If your key is not in there, you can import it: |
| 36 | + |
| 37 | + $ gpg --import myprivatekey.gpg |
| 38 | + |
| 39 | +Check it has been imported: |
| 40 | + |
| 41 | + $ gpg --list-secret-keys --keyid-format LONG |
| 42 | + |
| 43 | +Copy the ID of your private key and register this key in `git-identity`: |
| 44 | + |
| 45 | + $ git identity --define-gpg <identity name> <gpgkeyid> |
| 46 | + |
| 47 | +Additional resources |
| 48 | +-------------------- |
| 49 | + |
| 50 | +Here are some interesting resources you might want to read if you wish to go deeper on GPG with git: |
| 51 | + |
| 52 | +* [Generating a new GPG key](https://help.github.com/articles/generating-a-new-gpg-key/) |
| 53 | +* [Adding a new GPG key to your GitHub account](https://help.github.com/articles/adding-a-new-gpg-key-to-your-github-account/) |
| 54 | +* [Installing your GPG key in git](https://help.github.com/articles/telling-git-about-your-gpg-key/) |
0 commit comments