This steps worked on Ubuntu Linux
Listing existing keys
gpg --list-secret-keys
gpg --list-secret-keys --keyid-format LONG
Generating a key
Use
gpg --gen-key
Making Git use the key to sign the commits
git config --global user.signingkey [THE KEY ID]
git commit -S -m 'Your commit message'
Make Git automatically sign all the commits
git config --global commit.gpgsign true
git config commit.gpgsign false
Show your key public block using this command
gpg --armor --export [THE KEY ID]
You need to tell Gitlab and Github about your key, by adding it to the list of your account keys from this page (Github)
brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent