0%

git中使用GPP来提交到github

git中使用GPP来提交到github

If you do not have an GPG key, you can generate a new key by using gpg to use in git commit and tags to identify that it’s absolute you did it.

生成一个新的GPG key

以MacOSX系统为例.

1
2
3
4
# first install gpg on MacOSX
$ brew install gpg
# then gpg-suite to save passwd in MacOSX chains
$ brew cask install gpg-suite

生成key

1
$ gpg --full-generate-key

列出GPG key

1
2
3
4
5
6
7
8
9
$ gpg --list-secret-keys --keyid-format LONG

/Users/<userid>/.gnupg/pubring.gpg
----------------------------------
sec rsa4096/ABCDABCDABCDABCD 2015-11-17 [SC] [expires: 2020-11-15]
SASASASASASASASAASASASASASASASASASASASAS
uid [ultimate] Username (userid) <email@address.com>
ssb rsa4096/ABCDABCDABCDABCD 2015-11-17 [E] [expires: 2020-11-15]

or

1
2
3
4
5
6
7
8
# or for SHORT format
$ gpg --list-secret-keys --keyid-format SHORT
/Users/<userid>/.gnupg/pubring.gpg
----------------------------------
sec rsa4096/ABCDABCD 2015-11-17 [SC] [expires: 2020-11-15]
SASASASASASASASAASASASASASASASASASASASAS
uid [ultimate] Username (userid) <email@address.com>
ssb rsa4096/ABCDABCD 2015-11-17 [E] [expires: 2020-11-15]

The different between LONG and SHORT is the .

将GPG keys添加到Github

If you want show a Verified label in Github, now you should add a GPG key in github setting.

Using the following command to get a ASCII-armored format of GPG then paste it in Github,
following Settings -> SSH and GPG keys -> New GPGP key

1
2
3
4
5
6
$ gpg --armor --export <key ID>

-----BEGIN PGP PUBLIC KEY BLOCK-----

<ASCII armored PGP Public Key Block (exported to a *.asc file)>
-----END PGP PUBLIC KEY BLOCK-----

the is ABCDABCD when using LONG or SHORT.

在git终端中配置

GPG sign签名默认情况下是禁用的,可以通过以下设置来使能这个功能。

1
2
3
4
5
6
$ gpg --list-secret-keys --keyid-format SHORT

#if no key found then generate new one
# replace the ABCDABCD using your own key ID
$ git config --global user.signingkey ABCDABCD
$ git config --global commit.gpgsign true

Some post said that you should do export GPG_TTY=$(tty),
I am not encounter this problems fortunately.

使用SourceTree来提交签名

在SourceTree中的 “Enable GPG key signing for commit” 一直是灰色的,并且终端中支持提交前,而SourceTree无法push成功,此时主要是以为gpg程序没有设置,执行下面的命令,然后重启SourceTree即可解决。

1
2
3
4
$ which gpg
/usr/bin/gpg

$ git config --global gpg.program /usr/bin/gpg

其中的gpg路径不同的操作系统可能不同,需要根据具体情况来设置。

error: gpg 数据签名失败

在提交的时候,出现

1
2
error: gpg 数据签名失败
fatal: 写提交对象失败

解决方法,在zshrc中加上一句export GPG_TTY=$(tty),然后重启gpg-agent就可以了

重启命令为

1
$ gpgconf --kill gpg-agent
处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道