Git: GPG sign multiple previous commits
Contents
For my first contribution to kubefirst (#712), I was asked to sign all commits in my PR. I wanted to avoid touching every commit one by one.
Here is how I did that:
Creating a gpg key
First I created a gpg key using:
|
|
You will be prompted for various information, such as name, email, etc. These should match your information on your GitHub Account.
Importing the GPG Key to GitHub
Once done, you will have to import the generated GPG public key to your GitHub profile. To do so, you wil have to output it, using the following commands
|
|
You can then copy the public key (including the header & footer lines) and paste it in your GitHub GPG Settings (https://github.com/settings/keys)
Sign all commits in the PR
Last but not least, I had to sign all commits in the PR. I found a neat oneliner to archive that. This oneliner uses interactive rebasing to sign every commit:
|
|
It will open up the interactive rebase TUI, you can double check and then proceed by confirming (usually closing the $EDITOR
). If you have given your gpg-key at passphrase a window should open up, prompting you for the passphrase.
Once done, I efficiently signed all commits without touching every single one. You can once again double-check your history using, before you can push the commits (you will have to use --force
, because the SHASUMS of the commits have been altered).
|
|
if everything worked correctly, GitHub should list your commits now as verified :
Sign commits per default
For all future commits, you can configure your git to sign all commits per default by running:
|
|
Author Tom Morelly
LastMod 2024-03-31 (5b5a668)