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

"git -C other_repo" returns wrong GIT_DIR and GIT_COMMON_DIR when run via alias in worktree

From
Jjumps_dollies_9s@icloud.com <jumps_dollies_9s@icloud.com>
Date
Sep 28, 2026, 13:38 UTC
Message-ID
<85B2D383-8519-4A76-8DED-459067060B61@icloud.com>

Hello, I’ve discovered an interesting and likely very niche bug. When using "git -C other_repo …” from the worktree, the values of GIT_DIR and GIT_COMMON_DIR reflect those of the worktree, not the other repo, but only when run via an alias. If run directly, then GIT_DIR and GIT_COMMON_DIR reflect the expected values for the other repo.

This has knock-on effects, notably when using “git -C submodule_path restore” in an alias, it copies the contents of the parent repository.
Using “git -C other_repo …” from the original clone returns the correct values for GIT_DIR and GIT_COMMON_DIR. This occurs only with worktrees.

I’ve collected a reproduction into a single script https://gist.github.com/MayaBarriaultRT/76d864f005bcff2fccb02444c48a3343

I’ve reproduced this with Git v2.52.0 on AlmaLinux 9.7, v2.54.0 on macOS 26.4, and v2.55.0 built from source using ubuntu:26.04 Docker image.
Maya Barriault
Message 1 of 1 in “"git -C other_repo" returns wrong GIT_DIR and GIT_COMMON_DIR when run via alias in worktree”
  1. jumps_dollies_9s@icloud.comSep 28, 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.