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

Step by step

$ 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

Generating a new GPG key
Git error: gpg failed to sign the data on Linux

    分享到:
分类: Git

发表评论

电子邮件地址不会被公开。 必填项已用*标注

验证码 *