Killed Git Process Leaves index.lock Behind: How Git's Lock Files Work

A coding agent killed mid-commit can leave .git/index.lock on disk, causing later git operations to fail with a file-exists error. Git avoids partial writes by creating a lock file exclusively, writing changes into it, and atomically renaming it over the original, or deleting it to roll back. Cleanup on exit relies on signal handlers for SIGINT, SIGHUP, SIGTERM, SIGQUIT and SIGPIPE, but SIGKILL cannot be caught, so the lock survives. The real index is unaffected by the dead process, so deleting the stale lock is generally safe, though whatever was staged in it is discarded. The article also notes that plain git commit releases its lock before running hooks, which limits how long the lock is held.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in