public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Derrick Stolee <stolee@gmail•com>
To: Matthew Gabeler-Lee <fastcat@gmail•com>, git@vger•kernel.org
Subject: Re: bug: for-each-repo malfunctions in worktree due to GIT_DIR
Date: Mon, 23 Feb 2026 20:52:10 -0500	[thread overview]
Message-ID: <1d4d795d-3a0b-47c5-864f-56f3c7601d39@gmail.com> (raw)
In-Reply-To: <CABpCjbY=wpStuhxqRJ5TSNV3A-CmN-g-xZGJOQGSSv3GYhs2fQ@mail.gmail.com>

On 2/23/26 5:58 PM, Matthew Gabeler-Lee wrote:
> 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


      reply	other threads:[~2026-02-24  1:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23 22:58 bug: for-each-repo malfunctions in worktree due to GIT_DIR Matthew Gabeler-Lee
2026-02-24  1:52 ` Derrick Stolee [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d4d795d-3a0b-47c5-864f-56f3c7601d39@gmail.com \
    --to=stolee@gmail$(echo .)com \
    --cc=fastcat@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox