I recently found the same secret key not available
error and a few more along the way, like GPG agent not found for instance.
In my case I wanted to get commits signed and showing as verified on GitHub.
Below are the complete steps to get it working on Windows 10 x64:
Install GPG
I installed GPG 2.3.1 with winget
like so:
C:\> winget install GnuPG.GnuPG
Verify it with:
C:\> gpg --version
Generate GPG key
C:\> gpg --full-generate-key
Add your real name and e-mail, the same as used in the GitHub account.
The key must be at least 4096 bits.
Export the key in ASCII armor format
First list the key:
C:\> gpg --list-secret-keys --keyid-format=long
sec rsa4096/[short-key] 2021-06-14 [SC]
Then export it:
C:\> gpg --armor --export [short-key]
Copy the key including the BEGIN/END text.
-----BEGIN PGP PUBLIC KEY BLOCK-----
[huge-ascii-key]
-----END PGP PUBLIC KEY BLOCK-----
Add the GPG armor ASCII key to the GitHub account
Go to Profile
> Settings
> SSH and GPG keys
> New GPG key
Or please follow these visual instructions.
Configure Git to sign all commits by default
C:\> git config --global user.signingkey [short-key]
C:\> git config --global commit.gpgsign true
C:\> git config --global gpg.program "C:/Program Files (x86)/gnupg/bin/gpg"
Set GPG environment variable for the GPG Agent
Check for GPG agent:
gpg-agent --version
Set the environment variable:
GNUPGHOME=%USERPROFILE%\AppData\Roaming\gnupg
Done
The resulting .gitconfig
would have the user section like so:
[user]
name = Your Name
email = [email protected]
signingkey = [short-key]
[commit]
gpgsign = true
[gpg]
program = C:/Program Files (x86)/gnupg/bin/gpg