Signing Git Commits Using PowerShell
Guide written for Windows Version: 11 Pro
If you do not have GPG Keys setup refer to Setting up GPG Keys with Powershell
Configuring Git Global Variables
- List gpg keys
Note: The key ID is the part after / on the line starting with “sec”
- Configure Git to Use Your GPG key
- Optional: To configure Git to sign all your commits by default
- Print your public GPG Key
Adding Your GPG key to GitLab
- Sign in to GitLab
- Go to your user settings, then to the “GPG Keys” section.
- Paste your public GPG key into the text area and click “Add key.”
- Verify
- Commit and push changes to your repository.
Common Errors
1. No Secret Key
Background Information:
Git for Windows comes with a minimal version of GnuPG. This version uses the
~/.gnupg/
,C:\Users\YourUsername\.gnupg\
, directory for configuration files and key storage.gpg4win configures GnuPG to use
%APPDATA%\gnupg
for configuration files and key storage.
- Check Git global configuration
Look for gpg.program
variable. If there is no gpg.program
entry, Git will attempt to use the minimal install discussed above.
- Set the GPG Program in Git Configuration
Attention
Your path may differ; please confirm before running this command.
- Confirm Change
2. Bad Data Signature
- Check for Matching Keys
- List the key ID Git is configured to use
- Check for the Matching Key
3. No Agent Running
- Start Agent