"git -C other_repo" returns wrong GIT_DIR and GIT_COMMON_DIR when run via alias in worktree
- From
- jumps_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