git/list[1] front-page[2] threads[3] people[4] search[5] about
 

HEAD.lock and git maintenance

From
DAdavid asraf <dasraf9@gmail.com>
Date
May 22, 2025, 16:53 UTC
Message-ID
<CANi7bVAkNc+gY1NoXfJuDRjxjZLTgL8Lfn8_ZmWsvLAoiLPkNg@mail.gmail.com>
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.
What did you do before the bug happened? (Steps to reproduce your issue)

We have a system that runs many git commands on a local repo connected to a remote repo on GitHub via HTTPS. Our system creates many commits and works with many un-staged files. Every once in a while, we run the following sequence of commands:

git stash --all
git checkout b1
git remote -v
git fetch
git status --branch --porcelain=v1 -u
git checkout b2
git stash pop
We start this sequence from branch b1 and record the output for internal use.
What did you expect to happen? (Expected behavior)
We expected git checkout b2 to succeed consistently.
What happened instead? (Actual behavior)
git checkout b2 sometimes fails because the HEAD.lock file already exists.
What's different between what you expected and what actually happened?

The git checkout b2 command, which previously succeeded consistently, now occasionally fails due to the presence of a HEAD.lock file. This issue started occurring after upgrading Git from version 2.39.5 to 2.47.2.

Anything else you want to add:

Using GIT_TRACE_PERFORMANCE, we noticed that a Git maintenance process (/usr/libexec/git-core/git maintenance run --auto --no-quiet --detach) sometimes starts after the git fetch command, occasionally in detached mode. We suspect this operation is causing the issue because we've verified that the git maintenance command requires HEAD.lock before it starts running. We are considering setting maintenance.autoDetach to false. We are unsure if this is a bug or if it is working as intended, and would appreciate your comments on this.

Thanks, David.
Please review the rest of the bug report below.
You can delete any lines you don't wish to share.
[System Info]
git version: 2.47.2
Next: Patrick Steinhardt
Message 1 of 4 in “HEAD.lock and git maintenance”
  1. david asrafMay 22, 2025
  2. Patrick SteinhardtMay 26, 2025
  3. Emily ShafferMay 27, 2025
  4. Patrick SteinhardtMay 28, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.