Refer to @sideshowbarker, and @Xavier Ho solution, I solved my problem via following steps.
Assume gpg2 installed by brew,
git config --global gpg.program gpg2
brew install pinentry
gpgconf --kill gpg-agent
gpg2 -K --keyid-format SHORT
// no key found then generate new one
gpg2 --gen-key
gpg2 -K --keyid-format SHORT
.../.gnupg/pubring.gpg
sec rsa2048/0A61C6FC 2017-06-29 [SC] [expires: 2019-06-29]
git config --global user.signingkey 0A61C6FC
Reminded by my colleague, need to append
export GPG_TTY=$(tty)
to ~/.zshrc if using zsh, else append to ~/.bash_profile
For macOS,
the gpg2 is combined with gpg in brew and hence the gpg command is pointed to gpg2
brew install gpg2
brew info gpg
gnupg: stable 2.2.6 (bottled)
git config --global gpg.program gpg
gpg -K --keyid-format SHORT
and there has pinentry-mac for passphrase entry
brew install pinentry-mac
vim ~/.gnupg/gpg-agent.conf
Add line
pinentry-program /usr/local/bin/pinentry-mac
Reminded by my colleague, need to append
export GPG_TTY=$(tty)
to ~/.zshrc if using zsh, else append to ~/.bash_profile
git config --local user.signingkey
to the correct key and it'll autosign again. and maybe unset the global one withgit config --global --unset user.signingkey
– Paralyzegit config --global user.email 'SAME EMAIL'
– Caseworkecho "test" | gpg --clearsign
, I have found out that there is a problem withgpg
itself. Therefore, I addedexport GPG_TTY=$(tty)
to.zshrc
. – Rattlebrained