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

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

From
MGMatthew Gabeler-Lee <fastcat@gmail.com>
Date
Feb 23, 2026, 22:58 UTC
Message-ID
<CABpCjbY=wpStuhxqRJ5TSNV3A-CmN-g-xZGJOQGSSv3GYhs2fQ@mail.gmail.com>

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.

Observed with git 2.51.0 from Ubuntu 25.10. I haven't tested explicitly with latest, but I took a quick look at git.c and for-each-repo.c changes between there and master and didn't see anything that looked like it would affect this behavior.

PS: please CC me on replies
Next: Derrick Stolee
Message 1 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.