• Change Git default settings;
  • Use GPG key to sign the Git commits.

Step by step

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ git config --global core.editor "vim"


# config your identity
git config --global user.email "YOUR_EMAIL"
git config --global user.name "YOUR_NAME"

# enable gpg signed commit
git config --global commit.gpgsign true

# generate gpg key
## git >= 2.1.17
gpg --full-generate-key
# or gpg --gen-key
## git < 2.1.17
gpg --default-new-key-algo rsa4096 --gen-key

# check your key id
$ gpg --list-secret-keys --keyid-format LONG
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
/home/triplez/.gnupg/pubring.kbx
--------------------------------
sec   rsa4096/96B4168C3D454E11 2018-11-28 [SC]
      6B0B48B063F8F592CE9006DE96B4168C3D454E11
uid                 [ultimate] Zhenzhen Zhao (my gpg) <me@triplez.cn>
ssb   rsa4096/435B8EB04CBF8E8D 2018-11-28 [E]

gpg --armor --export 96B4168C3D454E11
# copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK-----, then add it to the GitHub

# set user to sign with this gpg key
git config --global user.signingkey 96B4168C3D454E11

References


知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。