Git commit signing with GPG keys adds an extra layer of security and authenticity to your code contributions. This guide will walk you through the process of setting up GPG signing for your Git commits and troubleshoot common issues.
Setting Up GPG Signing for Git Commits
1. Create and publish your GPG Key
2. List your GPG keys to find the KEY_ID
gpg -K --keyid-format=long
3. Configure Git to use your GPG key
Replace KEY_ID
with your key found from the previous step.
git config --global user.signingkey KEY_ID
git config --global commit.gpgsign true
# OR, to make the changes for the current git repo:
git config user.signingkey KEY_ID
git config commit.gpgsign true
4. Add your GPG public key to your GitHub or GitLab account.
Signing Commits
With the above configuration, Git will automatically sign your commits. If you want to sign a commit manually, use:
git commit -S -m "Your commit message"
Common Issues and Solutions
GPG Input Issues
If you encounter GPG input problems, try setting the GPG_TTY environment variable:
export GPG_TTY=$(tty)
Add this line to your shell configuration file (e.g., .bashrc
or .zshrc
) for a permanent fix.
GPG Agent Problems
If the GPG agent isn’t running, start it manually:
gpg-agent --daemon
Verifying Signed Commits
To verify a signed commit:
git verify-commit COMMIT_HASH
Conclusion
Implementing GPG signing for your Git commits enhances the security and trustworthiness of your code contributions. By following this guide, you can easily set up and troubleshoot GPG signing in your Git workflow.
Happy developing!