THE GITHTML FIELD GUIDE
Handle an existing Git index.lock without risking concurrent work
An index.lock file protects an index update from concurrent writers. If Git says it already exists, first check for another Git process, editor-driven operation, or interrupted command. Do not delete a lock while its owner may still be running. Only a verified stale lock should be removed, using the exact repository-specific path.
Treat the lock as coordination, not clutter
A second terminal, an editor’s source-control panel, or a long-running commit hook can legitimately hold the index lock. Removing it while that operation is active can allow competing writes and damage the intended update. Wait for or investigate the known operation instead of assuming the file is abandoned because the terminal appears idle.
A crash or forced termination can leave a stale lock. Before concluding that happened, check active processes and the application that initiated Git, using your operating system’s normal process tools. Preserve the exact error message and repository location. Do not search broadly for every .lock file and delete them; different locks protect different resources.
Resolve the exact lock location
Git can locate its metadata path even when .git is a file pointing elsewhere. Use that path rather than assuming a directory layout. The commands below inspect context; they intentionally do not include an unconditional removal command. If a process is still active, let it finish or follow its documented cancellation procedure.
- Verify no Git process or related tool is still using this repository, including background source-control integrations and commit hooks.
- If the lock is demonstrably stale, remove only that exact lock file through a deliberate file operation, keeping the index and all other metadata untouched.
git rev-parse --show-toplevel
git rev-parse --git-path index.lock
git status --shortVerify after the interruption
Rerun status and inspect staged and unstaged changes before retrying the original write. An interrupted operation may not have completed the update you expected, even after the lock obstacle is gone. If Git reports index corruption or another error, preserve the repository and investigate that specific condition rather than deleting the index as a generic next step.
Repeated stale locks suggest a failing tool, hook, filesystem, or interrupted process worth diagnosing. Record which command held the lock and how it ended. A one-time safe cleanup should not become a script that removes locks automatically before every Git operation, because that would bypass the coordination mechanism precisely when it is needed.
- If a commit editor is still open, inspect that session before calling its lock stale. The foreground terminal may appear quiet while Git waits for the editor or a hook. Finish or cancel through the owning tool’s normal flow, then check whether the lock disappears naturally.
- After a confirmed stale-lock removal, inspect the index entry for the file involved in the interrupted add operation. Compare staged and working versions to establish whether staging completed. Retry only that intended update; a broad add could conceal the interruption by including unrelated changes.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.