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

Re: bug: for-each-repo malfunctions in worktree due to GIT_DIR

From
Derrick Stolee <stolee@gmail.com>
Date
Feb 24, 2026, 01:52 UTC
Message-ID
<1d4d795d-3a0b-47c5-864f-56f3c7601d39@gmail.com>
In-Reply-To
<CABpCjbY=wpStuhxqRJ5TSNV3A-CmN-g-xZGJOQGSSv3GYhs2fQ@mail.gmail.com>
On 2/23/26 5:58 PM, Matthew Gabeler-Lee wrote:
Show 18 quoted lines
> I noticed some scripts I have that utilize `git for-each-repo` don't
> work if I run them from within a git worktree, but they do work fine
> from within other directories, including the parent git clone of those
> worktrees. The symptom is that the command I pass to `for-each-repo`
> is run as if from within the worktree each time, instead of the repos
> fetched from the corresponding config entry.
> 
> After a bit of sleuthing with strace, I think I identified the cause:
> $GIT_DIR is set in the `git for-each-repo` process, and gets passed to
> the child git invocations it launches.
> 
> And thus, from within that worktree, `git for-each-repo
> --config=foo.bar -- branch` becomes the equivalent of:
> 
> GIT_DIR=/worktree-parent/.git git -C /unrelated-repo branch
> 
> Which of course is not what the `for-each-repo` invocation would be
> expected to do.

You're absolutely right on this. It's a subtle oversight, as it's not one of the worktree-specific variables, but GIT_DIR is being set by the worktree logic.

I have a test and a fix on the way in [1]. You'll be CC'd when I send the patches after a CI run.

[1] https://github.com/gitgitgadget/git/pull/2056

Thanks, -Stolee

Previous: Matthew Gabeler-Lee
Message 2 of 2 in “bug: for-each-repo malfunctions in worktree due to GIT_DIR”
  1. Matthew Gabeler-LeeFeb 23, 2026
  2. Derrick StoleeFeb 24, 2026

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.