Table of Contents
2. Find Your GPG Key ID
3. Tell Git to Use Your GPG Key
4. Add GPG Public Key to GitHub/GitLab/Other Platforms
5. Fix Common Issues
? GPG "No Secret Key" Error
? Linux: GPG Pinentry Issues
? Windows: Using Git Bash
Bonus: Sign Tags
Home Development Tools git How to Sign Your Git Commits with a GPG Key

How to Sign Your Git Commits with a GPG Key

Aug 23, 2025 am 08:29 AM
git GPG Key

Generate or use an existing GPG key by installing GPG and running gpg --full-generate-key with RSA 4096-bit key size, matching your Git email, and setting a secure passphrase. 2. Find your GPG key ID using gpg --list-secret-keys --keyid-format LONG and extract the key ID (e.g., ABC1234567890DEF) from the sec line. 3. Configure Git to use the key by setting git config --global user.signingkey ABC1234567890DEF and ensuring git config --global user.email matches the GPG email, then optionally enable global signing with git config --global commit.gpgsign true or use git commit -S per commit. 4. Add your GPG public key to GitHub/GitLab by exporting it with gpg --armor --export ABC1234567890DEF and pasting the full block into the platform's GPG key settings. 5. Resolve common issues by verifying email and key ID match, ensuring GPG is in PATH, setting git config --global gpg.program appropriately for your OS, and exporting GPG_TTY=$(tty) in your shell profile to fix pinentry hangs. Optionally sign tags with git tag -s and verify with git tag -v, ensuring all systems use consistent emails and keys for verified, trusted commits.

How to Sign Your Git Commits with a GPG Key

Signing your Git commits with a GPG key adds a layer of authenticity and trust, proving that you are the true author of the changes. This is especially useful in team environments or open-source projects where verifying contributor identities matters. Here’s how to set it up step by step.

How to Sign Your Git Commits with a GPG Key

1. Generate or Use an Existing GPG Key

If you don’t already have a GPG key, you’ll need to generate one.

Install GPG if it’s not already installed:

How to Sign Your Git Commits with a GPG Key
# On macOS
brew install gnupg

# On Ubuntu/Debian
sudo apt-get install gnupg

# On Windows (via Git Bash or WSL)
# GPG usually comes with Git for Windows

Now generate a new GPG key:

gpg --full-generate-key

You’ll be prompted to:

How to Sign Your Git Commits with a GPG Key
  • Choose key type (select RSA and RSA)
  • Key size (use 4096)
  • Expiration period (optional)
  • Your name and email (must match your Git config!)
  • A passphrase (keep it secure)

Alternatively, use this command for a non-interactive version:

gpg --batch --generate-key <<EOF
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Name-Real: Your Name
Name-Email: your.email@example.com
Expire-Date: 0
Passphrase: your-passphrase
%commit
EOF

2. Find Your GPG Key ID

List your secret keys to get the key ID:

gpg --list-secret-keys --keyid-format LONG

Look for a line like:

sec   rsa4096/ABC1234567890DEF 2024-01-01 [SC]

Here, ABC1234567890DEF is your GPG key ID.

You can also extract just the key ID with:

gpg --list-secret-keys --keyid-format LONG your.email@example.com | grep ^sec | awk '{print $2}' | cut -d'/' -f2

3. Tell Git to Use Your GPG Key

Set the GPG key in your Git config:

git config --global user.signingkey ABC1234567890DEF

Also ensure your user email in Git matches the one used in the GPG key:

git config --global user.email "your.email@example.com"

Enable commit signing globally (optional):

git config --global commit.gpgsign true

Or sign individual commits by adding -S:

git commit -S -m "This commit is signed"

? If you don’t want to sign every commit globally, skip enabling commit.gpgsign and just use -S when needed.


4. Add GPG Public Key to GitHub/GitLab/Other Platforms

To get the verified badge on GitHub, you need to add your public key.

Export your public key:

gpg --armor --export ABC1234567890DEF

This outputs something like:

-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

Copy the entire block (including BEGIN and END lines), then:

  • GitHub: Go to Settings → SSH and GPG keys → New GPG key → Paste
  • GitLab: Settings → GPG Keys → Paste
  • Bitbucket: Similar process under account settings

Once added, your commits will show as "Verified" when pushed.


5. Fix Common Issues

? GPG "No Secret Key" Error

Even if you have the key, Git might not find it. Make sure:

  • The email in Git matches the GPG key exactly
  • You're using the correct key ID
  • Your GPG binary is in PATH

On macOS, you may need to set:

git config --global gpg.program gpg

? Linux: GPG Pinentry Issues

If signing hangs, it might be due to missing pinentry. Install it:

sudo apt install pinentry-gtk2  # or pinentry-tty

Set the GPG agent to use the right TTY:

export GPG_TTY=$(tty)

Add that to your shell profile (.zshrc, .bashrc) to avoid future issues.

? Windows: Using Git Bash

Make sure you’re using the GPG version bundled with Git:

git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"

And set:

export GPG_TTY=$(tty)

in your .bashrc.


Bonus: Sign Tags

GPG-signed tags are also useful:

git tag -s v1.0.0 -m "Signed release"

Verify with:

git tag -v v1.0.0

That’s it. With GPG signing enabled, your commits are cryptographically verified. It’s a small step for security, but a big one for trust in collaborative development. Just make sure your key is backed up and your email matches across systems.

Basically: generate key → set in Git → add public key to platform → sign commits. Not complex, but easy to miss a detail.

The above is the detailed content of How to Sign Your Git Commits with a GPG Key. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Ethena treasury strategy: the rise of the third empire of stablecoin Ethena treasury strategy: the rise of the third empire of stablecoin Jul 30, 2025 pm 08:12 PM

The real use of battle royale in the dual currency system has not yet happened. Conclusion In August 2023, the MakerDAO ecological lending protocol Spark gave an annualized return of $DAI8%. Then Sun Chi entered in batches, investing a total of 230,000 $stETH, accounting for more than 15% of Spark's deposits, forcing MakerDAO to make an emergency proposal to lower the interest rate to 5%. MakerDAO's original intention was to "subsidize" the usage rate of $DAI, almost becoming Justin Sun's Solo Yield. July 2025, Ethe

How to use 5,000 yuan to earn 500,000 yuan in the currency circle? How to use 5,000 yuan to earn 500,000 yuan in the currency circle? Aug 07, 2025 pm 08:42 PM

In the field of digital currency, a full range of variables and opportunities, increasing the principal of 5,000 to 500,000 means that one hundred times the asset appreciation needs to be achieved. This is not a simple math game, but a comprehensive test involving cognition, strategy, mentality and execution. It requires participants not to rely solely on luck, but also to have keen market insight and extraordinary risk management capabilities.

There is only one kind of person who makes money in the currency circle There is only one kind of person who makes money in the currency circle Jul 29, 2025 pm 03:24 PM

What can truly make money stably is countercyclical traders with anti-human characteristics. 1. They identify whales in the market FOMO by fighting emotional kidnapping, and capture wrongly killed assets when panic sell-offs; 2. Establish mechanized trading discipline and strictly implement stop-profit and stop-loss rules to fight greed and fear; 3. Use cognitive arbitrage thinking to discover institutional trends and trend opportunities in advance through on-chain data and code updates and other underlying information, and ultimately solidify emotional isolation, data decision-making and countercyclical operations into trading instincts, thereby continuing to make profits in the encrypted market with amplified human nature.

How to Amend the Previous Git Commit Message How to Amend the Previous Git Commit Message Aug 01, 2025 am 03:34 AM

Toamendthemostrecentcommitmessage,usegitcommit--amend-m"Yournewcommitmessage"ifthecommithasn’tbeenpushed;thisrewritesthelocalcommithistorywiththenewmessage.2.Toeditthemessageinyourdefaulteditor,rungitcommit--amendwithoutthe-mflag,allowingyo

Matrixport Market Observation: Bitcoin (BTC) giant whale shipments, Ethereum (ETH) continues to lead the rise, and capital flows become the focus of the market Matrixport Market Observation: Bitcoin (BTC) giant whale shipments, Ethereum (ETH) continues to lead the rise, and capital flows become the focus of the market Jul 30, 2025 pm 09:21 PM

Table of Contents Market Interpretation of the concentrated shipment of ancient giant whales, BTC prices quickly repair ETH close to $4,000 key position, polarization of pledge and fund demand, altcoin sector differentiation intensifies, Solana and XRP funds inflows highlight market hotspots pay attention to macro data and policy trends, and market fluctuations may intensify last week (July 22-July 28). BTC maintained a high-level oscillation pattern. The ETH capital inflow trend continues to improve, the ETH spot ETF has achieved net inflow for eight consecutive weeks, and the ETH market share has climbed to 11.8%. On July 25, affected by the massive selling of Galaxy Digital, BTC fell below $115,000 for a short time, reaching the lowest point

What are stablecoins? What are the top 10 stablecoins in market value? What are stablecoins? What are the top 10 stablecoins in market value? Aug 07, 2025 pm 10:57 PM

Stable coins are cryptocurrencies whose value is linked to stable assets such as the US dollar or gold. They aim to solve the problem of large price fluctuations in currencies such as Bitcoin. They achieve price stability through an anchoring mechanism and are mainly divided into three categories: 1. Stable coins with legal currency collateral, such as USDT and USDC, are supported by US dollar reserves, and users can exchange 1:1; 2. Stable coins with crypto assets collateral, such as DAI and crvUSD, are generated by over-collateralized digital assets such as Ethereum, and have decentralized characteristics; 3. Algorithmic stable coins, such as USDD, rely on algorithms to adjust supply and demand to maintain currency value, and have no direct asset collateral, and are at a high risk. The top 10 stablecoins currently ranked in market capitalization include: 1. USDT, the earliest and most liquid dollar stablecoins; 2. USDC, to comply with and

Wall Street Whale Devours Ethereum: Interpretation of the Pricing Power Battle Behind Purchase 830,000 ETH in 35 Days Wall Street Whale Devours Ethereum: Interpretation of the Pricing Power Battle Behind Purchase 830,000 ETH in 35 Days Aug 22, 2025 pm 07:18 PM

Table of Contents Two ancestry, two worldviews: The philosophical showdown between OG coins hoarding and Wall Street harvesting. Financial engineering dimensionality reduction strike: How BitMine reconstructs ETH pricing power in 35 days. New dealer spokesperson: TomLee and Wall Street narrative manipulation ecological reconstruction: How Wall Street Capital reshapes the ETH value chain. A small company that was originally unknown in Nasdaq increased its holdings from zero violence to 830,000 in just 35 days. Behind it is a survival philosophy showdown between the indigenous people in the currency circle and Wall Street Capital. On July 1, 2025, BitMine's ETH position was still zero. 35 days later, this family is unknown

How do I undo a staging operation? How do I undo a staging operation? Aug 02, 2025 am 01:26 AM

If you mistakenly add files to the temporary storage area in Git, you can use the gitrestore--staged or gitreset command to undo the operation. 1. To cancel the temporary storage of a single file, you can run gitrestore-staged file name or gitresetHEAD file name; 2. To cancel the temporary storage of all files at once, you can run gitrestore-staged. or gitreset; 3. If you have already submitted, you need to use gitreset-mixedHEAD~1 to undo the submission and keep the changes; 4. If you want to discard changes in the temporary storage and working directory at the same time, you can run gitrestore-staged-work

See all articles