Skip to content

Instantly share code, notes, and snippets.

@bahadiraraz
Last active November 14, 2024 18:51
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 File:

rm ~/.gnupg/[name-of-the-stale-lock-file].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.

@Pixlox
Copy link

Pixlox commented Feb 23, 2024

Thanks! This helped a ton.

@bmoncef-oa
Copy link

Thanks a lot 👍

in my case on macOS Catalia Version 10.15.7
the lock file here /Users/moncefbouallagui/.gnupg/public-keys.d/pubring.db.lock

@debborafernandess
Copy link

Kudos!

Thank you @bahadiraraz and @bmoncef-oa, you guys helped a lot!

@VanuPhantom
Copy link

VanuPhantom commented May 23, 2024

For users on Darwin (MacOS)

Expanding upon @bmoncef-oa's comment, use the following command:

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

This lets you list all lockfiles without manually exploring each subdirectory.

@harsh-rr
Copy link

harsh-rr commented Jun 6, 2024

Thank you @bahadiraraz and @bmoncef-oa :)

@nhd98z
Copy link

nhd98z commented Jun 25, 2024

It helps a lot.

@ernest-kiwele
Copy link

Helped a ton, thanks. For me the problem was that the "locked" file was missing altogether.

@aeltorio
Copy link

aeltorio commented Sep 1, 2024

@sandervanhooft
Copy link

Big thanks!

@barracuda156
Copy link

Thank you, this helped.

@PaulGoldschmidt
Copy link

Thanks @VanuPhantom, worked like a charm. Highly appreciated 🥇

@cw6365
Copy link

cw6365 commented Oct 1, 2024

👍

@belovanas
Copy link

thank you! it helped 🎉

@adamniedzielski
Copy link

Thank you for the write-up, this issue was hard to debug. What helped me as well was using GIT_TRACE like:

GIT_TRACE=1 git commit -m "Adam"

@sumanthyedoti
Copy link

This helped. Thanks.

@DhruvCha
Copy link

Legend

@lucas-livefront
Copy link

I think I am in love with you.

@bennythejudge
Copy link

thank you this just solved the problem after spending almost a day trying to fix it.

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