gastownhall/beads · error
failed to resolve target git directory: %w
Error message
failed to resolve target git directory: %w
What it means
inspectWorktreeTarget runs `git rev-parse --absolute-git-dir` inside the target worktree to pin its git directory. If that command fails, this wrapped error is returned. It means git could not determine the .git directory for the worktree — the worktree is broken, missing, or git itself errored.
Source
Thrown at cmd/bd/worktree_cmd.go:957
detached bool
bare bool
locked bool
lockReason string
prunable bool
pruneReason string
status string
statusFingerprint string
registryID string
}
func inspectWorktreeTarget(
ctx context.Context,
git *worktreeRemovalGit,
worktree registeredWorktree,
) (pinnedWorktreeTarget, error) {
gitDirOutput, err := git.output(ctx, worktree.path, "rev-parse", "--absolute-git-dir")
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to resolve target git directory: %w", err)
}
gitDir := filepath.Clean(strings.TrimSpace(string(gitDirOutput)))
commonDirOutput, err := git.output(
ctx,
worktree.path,
"rev-parse",
"--path-format=absolute",
"--git-common-dir",
)
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to resolve target common git directory: %w", err)
}
headOutput, err := git.output(
ctx,
worktree.path,
"rev-parse",
"--verify",
"--quiet",View on GitHub (pinned to 71377f2769)
Solutions
- Inspect the wrapped git error; reproduce with `git -C <path> rev-parse --absolute-git-dir` to see the raw failure.
- If the directory is gone, run `git worktree prune` and clean the bd registry entry, then retry.
- If the .git file's gitdir pointer dangles (repo was moved), recreate the worktree with `git worktree add` and re-register it.
- Verify git is on PATH and the path is readable by the current user.
Example fix
// before bd worktree remove feature-x // error: failed to resolve target git directory: ... (directory deleted) // after git worktree prune bd worktree remove feature-x # registry now clean
Defensive patterns
Strategy: try-catch
Validate before calling
const probe = Bun.spawnSync(["git", "-C", worktreePath, "rev-parse", "--absolute-git-dir"]);
if (probe.exitCode !== 0) {
throw new Error(`worktree broken, prune instead: ${probe.stderr.toString()}`);
} Try / catch
try {
await bd("worktree", "remove", path);
} catch (e) {
if (String(e.message).includes("failed to resolve target git directory")) {
execSync("git worktree prune");
} else throw e;
} Prevention
- Never rm -rf worktree directories; use `git worktree remove`.
- Check `git worktree list` health before scripted removals.
- Keep git on PATH and reasonably modern (>= 2.31).
- Avoid moving the main repo after creating worktrees.
When it happens
Trigger: Removal or revalidation on a registered worktree whose directory was deleted or corrupted, so git cannot resolve its git dir; git missing from PATH; the worktree's `.git` file points to a nonexistent gitdir; context cancellation kills the git subprocess.
Common situations: Someone deleted the worktree with rm -rf but the registry still lists it; a network-mounted worktree became unreadable; the main repo was moved so the .git file's gitdir pointer dangles; interrupted worktree creation.
Related errors
- failed to resolve target common git directory: %w
- target HEAD does not resolve to a commit: %w
- git returned invalid commit object ID %q
- git rev-parse timed out after %s
- failed to inspect created worktree cleanliness: %w %s
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/7a99ecd0899d61a7.
Report an issue: GitHub.