Skip to content

Separate git dir: {{ repo_path }} resolves to the git directory's parent, not the work tree #4235

Description

@zengzheqing

Summary

With a repository whose git directory lives outside the work tree (git init --separate-git-dir <store>, so .git is a file pointing at <store>), wt switch --create resolves {{ repo_path }} to the parent of the git directory, not to the work tree. The new worktree is created next to the store, and wt list shows the main worktree's path as the store as well.

Repro (wt v0.79.0, macOS, clean HOME with no user config)

mkdir -p repro/store repro/work repro/home
git init --separate-git-dir "$PWD/repro/store/repo.gitdir" repro/work
git -C repro/work commit -q --allow-empty -m init
cd repro/work
HOME="$PWD/../home" wt switch --create probe --no-cd --format=json

Output:

{"action":"created","branch":"probe","path":"<…>/repro/store.probe","created_branch":true,"base_branch":"main"}

Expected path is <…>/repro/work.probe (a sibling of the work tree, per the default {{ repo_path }}.{{ branch }} template).

wt list in the same state:

  Branch  Status  …  Path            Commit    Age  Message
^ main    ·  ·^      .               562ed3b   now  init
+ probe       _      ../store.probe  562ed3b   now  init

Likely cause

git worktree list itself reports the git directory as the main worktree entry in this layout:

<…>/repro/store/repo.gitdir 562ed3b [main]
<…>/repro/store.probe       562ed3b [probe]

so anything deriving the repo path from that first line lands on the store. Running git worktree repair (which writes the <store>/gitdir backlink, content <…>/repro/work/.git) does not change the result: a second wt switch --create probe2 still lands at <…>/repro/store.probe2.

Two sources that do give the work tree in this layout: git rev-parse --show-toplevel run from the main work tree, or the <gitdir>/gitdir backlink file (present after git worktree repair, absent right after git init --separate-git-dir).

Workaround

A per-project entry with an absolute worktree-path in the user config avoids the wrong placement, but wt list still shows the store as the main worktree's path.

Environment

  • wt v0.79.0 (also the latest release as of 2026-09-21)
  • git 2.x, macOS 26
  • 7 repositories on this machine use this layout (git dir kept outside a cloud-synced folder); all reproduce.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions