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 | # first install gpg on MacOSX |
生成key
1 | $ gpg --full-generate-key |
列出GPG key
1 | $ gpg --list-secret-keys --keyid-format LONG |
or
1 | # or for SHORT format |
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 | $ gpg --armor --export <key ID> |
the
is ABCDABCD when using LONG or SHORT.
在git终端中配置
GPG sign签名默认情况下是禁用的,可以通过以下设置来使能这个功能。
1 | $ gpg --list-secret-keys --keyid-format SHORT |
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 | $ which gpg |
其中的gpg路径不同的操作系统可能不同,需要根据具体情况来设置。
error: gpg 数据签名失败
在提交的时候,出现
1 | error: gpg 数据签名失败 |
解决方法,在zshrc中加上一句export GPG_TTY=$(tty)
,然后重启gpg-agent就可以了
重启命令为
1 | $ gpgconf --kill gpg-agent |