Signing and verifying commits Signing and verifying merges • Signing and verifying tags
Signing merges from one branch into another is achieved via the --verify-signatures flag to git merge, which is important to understand how it works:
Verify that the tip commit of the side branch being merged is signed with a valid key, i.e. a key that has a valid uid: in the default trust model, this means the signing key has been signed by a trusted key. If the tip commit of the side branch is not signed with a valid key, the merge is aborted.
In examining the underlying code1, this appears to work by checking the latest commits of the branches involved in the merge, not every commit:
/*
* All the rest are the commits being merged; prepare
* the standard merge summary message to be appended
* to the given message.
*/
remoteheads = collect_parents(head_commit, &head_subsumed,
argc, argv, &merge_msg);
if (!head_commit || !argc)
usage_with_options(builtin_merge_usage,
builtin_merge_options);
if (verify_signatures) {
for (p = remoteheads; p; p = p->next) {
verify_merge_signature(p->item, verbosity,
check_trust_level);
}
}In this exercise, the process for signing and verifying merges is covered including:
- Explicitly sign and verify commits
- Troubleshooting problems
- Optional Git configurations to sign and verify all commits
Note This exercise uses preparation done previously in "Signing and verifying commits".
-
Create a branch where changes will be committed towards v1.0.0 release
git checkout -b feature/v1.0.0
-
Create a simple "Hello world!" shell script
cat << 'EOF' > hello-world.sh #! /usr/bin/env bash echo "Hello world!" EOF chmod 755 hello-world.sh ./hello-world.sh
resulting in:
Hello world! -
Commit "Hello world!" shell script to feature branch
git add . git commit -m "Adding hello-world script for v1.0.0 release"
-
Checkout the default branch to prepare for merging the feature branch
git checkout main
-
Update the README prior to merging our changes for the new script
cat << 'EOF' >> README.md ## Hello world! The `v1.0.0` release contains the `hello-world.sh` script, which understandably displays `Hello world!`. EOF
-
Commit updated README changes prior to merging our changes
git add . git commit -m "Expanding README for upcoming feature"
-
Merge the feature branch, ensuring signatures are verified
git merge --verify-signatures feature/v1.0.0 -m "Merging in work towards v1.0.0 release"
Possible results:
-
Commit 666e636 has a good GPG signature by andyfeller@github.com Merge made by the 'ort' strategy. hello-world.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 hello-world.sh🥳 Congratulations! SSH merge signing is good.
-
fatal: Commit 666e636 does not have a GPG signature.😥 Do not to worry! This is error is likely due to the last commit not being signed or not trusted signer.
For more information about signing merges, see "
git merge --verify-signatures". -
-
Confirm logs show SSH commit sign status
git log
Possible results:
-
commit 28c46b890121f042e86d7d1c1b58e150b8ac9948 (HEAD -> main) Good "git" signature for andyfeller@github.com with ED25519 key SHA256:kanlHE9MI77O18EdnFxgEnzc3v1rxJHlW475IbnHdG8 Merge: ba5a622 666e636 Author: Andy Feller <andyfeller@github.com> Date: Sat Sep 10 19:55:34 2022 -0400 Merging in work towards v1.0.0 release commit ba5a622501be61cc531c0732fd005c2dccb34944 Good "git" signature for andyfeller@github.com with ED25519 key SHA256:kanlHE9MI77O18EdnFxgEnzc3v1rxJHlW475IbnHdG8 Author: Andy Feller <andyfeller@github.com> Date: Sat Sep 10 19:55:26 2022 -0400 Expanding README for upcoming feature commit 666e6364fc8e3156e31de42b103dca58a0ff7a62 (feature/v1.0.0) Good "git" signature for andyfeller@github.com with ED25519 key SHA256:kanlHE9MI77O18EdnFxgEnzc3v1rxJHlW475IbnHdG8 Author: Andy Feller <andyfeller@github.com> Date: Sat Sep 10 19:53:01 2022 -0400 Adding hello-world script for v1.0.0 release commit 14512033ae98ddb55eaebeedb27fdb78ae6cac49 Good "git" signature for andyfeller@github.com with ED25519 key SHA256:kanlHE9MI77O18EdnFxgEnzc3v1rxJHlW475IbnHdG8 Author: Andy Feller <andyfeller@github.com> Date: Sat Sep 10 19:49:07 2022 -0400 Initialize workspace repository README🥳 Congratulations! SSH merge verification setup is good.
-
-
Configure additional SSH merge signing and verifying for workshop repository specifically:
git config merge.verifySignatures trueNote To globally configure SSH signing and verifying, use the
--globalflag:git config --global merge.verifySignatures trueFor more information about these Git configuration options, see
merge.verifySignatures.
At the end of this exercise, the repository should look like:
Next: Signing and verifying tags
