Skip to content

Instantly share code, notes, and snippets.

@bahadiraraz
Last active April 17, 2025 00:39
Show Gist options
  • Save bahadiraraz/f2fb15b07e0fce92d8d5a86ab33469f7 to your computer and use it in GitHub Desktop.
Save bahadiraraz/f2fb15b07e0fce92d8d5a86ab33469f7 to your computer and use it in GitHub Desktop.
Git Commit Freeze Due to GPG Lock Issues (Solution)

Git Commit Freeze Due to GPG Lock Issues

If you encounter a problem where you cannot commit changes in Git – neither through the terminal nor via the GitHub Desktop application – the issue might be a freeze during the Git commit process. This is often caused by GPG lock issues. Below is a concise and step-by-step guide to resolve this problem.

Solution Steps

1. Check for GPG Lock Messages

Open your terminal and try to perform a GPG operation (like signing a test message). If you see repeated messages like gpg: waiting for lock (held by [process_id]) ..., it indicates a lock issue.

For example:

❯ echo "test" | gpg --clearsign

gpg: waiting for lock (held by 3571) ...
gpg: waiting for lock (held by 3571) ...
gpg: waiting for lock (held by 3571) ...

2. Locate and Remove Stale Lock Files

List Lock Files:

For Linux:

ls -l ~/.gnupg/*.lock

For MacOS (Darwin):

ls -l ~/.gnupg/**/*.lock

This command lists all lockfiles in ~/.gnupg and its subdirectories without manual exploration.

Remove the Identified Stale Lock Files:

For general lock files:

rm ~/.gnupg/[name-of-the-stale-lock-file].lock

For Linux systems, if the above doesn't work, try removing the public keys database lock:

rm -f ~/.gnupg/public-keys.d/pubring.db.lock

image

3. Restart GPG-Agent

After removing any stale lock files, it's important to reset the state of the GPG agent.

Command to Restart GPG-Agent:

gpgconf --reload gpg-agent

4. Test GPG Operations

To confirm if the issue is with GPG itself, try signing a simple test message:

Run:

echo "test" | gpg --clearsign

5. Retry Committing in Git

With the GPG lock issue resolved, try committing your changes again in Git.

@RaffaeleMondospedizioni

thank you <3

@askiiart
Copy link

Not sure what shell that's supposed to be on Linux, but I know for a fact that's not functional in fish or bash. Instead, you can use this:

find ~/.gnupg/ -name '*.lock'

Or in fish specifically, this will work as well

ls -l ~/.gnupg/**.lock

@MoonlyVibes
Copy link

thanks!

@demkkka
Copy link

demkkka commented Feb 12, 2025

thank you very much!

@kareem717
Copy link

For those using zshell, I like to use this function to quickly do this:

function restart-gpg() {
    echo "πŸ” Checking for GPG lock files..."
    
    # Remove any existing lock files
    if [ -d ~/.gnupg ]; then
        find ~/.gnupg -name "*.lock" -delete 2>/dev/null
        rm -f ~/.gnupg/public-keys.d/pubring.db.lock 2>/dev/null
        echo "πŸ—‘οΈ  Removed lock files"
    fi
    
    # Restart GPG agent
    echo "πŸ”„ Restarting GPG agent..."
    gpgconf --reload gpg-agent
    
    # Test GPG
    echo "πŸ§ͺ Testing GPG signing..."
    if echo "test" | gpg --clearsign > /dev/null 2>&1; then
        echo "βœ… GPG is working properly now!"
    else
        echo "❌ GPG is still having issues. You may need manual intervention."
    fi
}

Just add it to your .zshrc and use via restart-gpg. To quickly do this, use:

echo '
function restart-gpg() {
    echo "πŸ” Checking for GPG lock files..."
    
    # Remove any existing lock files
    if [ -d ~/.gnupg ]; then
        find ~/.gnupg -name "*.lock" -delete 2>/dev/null
        rm -f ~/.gnupg/public-keys.d/pubring.db.lock 2>/dev/null
        echo "πŸ—‘οΈ  Removed lock files"
    fi
    
    # Restart GPG agent
    echo "πŸ”„ Restarting GPG agent..."
    gpgconf --reload gpg-agent
    
    # Test GPG
    echo "πŸ§ͺ Testing GPG signing..."
    if echo "test" | gpg --clearsign > /dev/null 2>&1; then
        echo "βœ… GPG is working properly now!"
    else
        echo "❌ GPG is still having issues. You may need manual intervention."
    fi
}' >> ~/.zshrc && source ~/.zshrc

@vick08
Copy link

vick08 commented Feb 25, 2025

THanks for the solution. My problem .lock file was also under public keys, FWIW!

@sanam2405
Copy link

This helped. Thanks a lot!

@yonepv
Copy link

yonepv commented Mar 20, 2025

Big Thank you!!!!

@nosahama
Copy link

Thanks, this helped. Had to delete this - rm -f ~/.gnupg/public-keys.d/pubring.db.lock

@Rhobie07
Copy link

Rhobie07 commented Apr 8, 2025

thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment