Volume XXII, number 279Tuesday, October 6, 2026Latest message 36 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

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

1 messages between Sep 28, 2026 and Sep 28, 2026, from jumps_dollies_9s@icloud.com.

Plain Markdown or JSON for tools and agents.

jumps_dollies_9s@icloud.comSep 28, 2026, 13:38 UTC on lore

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

Back to recent threads

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