You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/07-git-tools/1-git-tools.asc
+196Lines changed: 196 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -603,8 +603,204 @@ If you want an easier way to test the stashed changes again, you can run `git st
603
603
604
604
This is a nice shortcut to recover stashed work easily and work on it in a new branch.
605
605
606
+
=== Signing Your Work
607
+
608
+
Git is cryptographically secure, but it's not foolproof. If you're taking work from others on the internet and want to verify that commits are actually from a trusted source, Git has a few ways to sign and verify work using GPG.
609
+
610
+
==== GPG Introduction
611
+
612
+
First of all, if you want to sign anything you need to get GPG configured and your personal key installed.
Additionally, you can configure `git log` to check any signatures it finds and list them in it's output with the `%G?` format.
749
+
750
+
[source,shell]
751
+
----
752
+
$ git log --pretty="format:%h %G? %aN %s"
753
+
754
+
5c3386c G Scott Chacon signed commit
755
+
ca82a6d N Scott Chacon changed the verison number
756
+
085bb3b N Scott Chacon removed unnecessary test code
757
+
a11bef0 N Scott Chacon first commit
758
+
----
759
+
760
+
Here we can see that only the latest commits is signed and valid and the previous commits are not.
761
+
762
+
In Git 1.8.3 and later, "git merge" and "git pull" can be told to inspect and reject when merging a commit that does not carry a trusted GPG signature with the `--verify-signatures` command.
763
+
764
+
If you use this option when merging a branch and it contains commits that are not signed and valid, the merge will not work.
765
+
766
+
[source,shell]
767
+
----
768
+
$ git merge --verify-signatures non-verify
769
+
fatal: Commit ab06180 does not have a GPG signature.
770
+
----
771
+
772
+
If the merge contains only valid signed commits, the merge command will show you all the signatures it has checked and then move forward with the merge.
773
+
774
+
[source,shell]
775
+
----
776
+
$ git merge --verify-signatures signed-branch
777
+
Commit 13ad65e has a good GPG signature by Scott Chacon (Git signing key) <[email protected]>
778
+
Updating 5c3386c..13ad65e
779
+
Fast-forward
780
+
README | 2 ++
781
+
1 file changed, 2 insertions(+)
782
+
----
783
+
784
+
You can also use the `-S` option with the `git merge` command itself to sign the resulting merge commit itself. The following example both verifies that every commit in the branch to be merged is signed and futhermore signs the resulting merge commit.
785
+
786
+
[source,shell]
787
+
----
788
+
$ git merge --verify-signatures -S signed-branch
789
+
Commit 13ad65e has a good GPG signature by Scott Chacon (Git signing key) <[email protected]>
790
+
791
+
You need a passphrase to unlock the secret key for
0 commit comments