gastownhall/beads · error

cannot find git executable: %w

Error message

cannot find git executable: %w

What it means

Before performing worktree removal, bd pins down the git executable via exec.LookPath("git") so subsequent subprocesses can't be repointed via PATH manipulation. If no `git` binary is found on PATH, this error is returned (wrapping exec.LookPath's exec.ErrNotFound).

Source

Thrown at cmd/bd/worktree_cmd.go:640

				if _, err := os.Stat(wt.Path); err == nil {
					return wt.Path, nil
				}
			}
		}
	}

	return "", fmt.Errorf("worktree not found: %s", name)
}

type worktreeRemovalGit struct {
	executable string
	env        []string
}

func newWorktreeRemovalGit() (*worktreeRemovalGit, error) {
	executable, err := exec.LookPath("git")
	if err != nil {
		return nil, fmt.Errorf("cannot find git executable: %w", err)
	}
	executable, err = filepath.Abs(executable)
	if err != nil {
		return nil, fmt.Errorf("cannot pin git executable path: %w", err)
	}
	if resolved, resolveErr := filepath.EvalSymlinks(executable); resolveErr == nil {
		executable = resolved
	}

	env := scrubWorktreeRemovalGitEnv(os.Environ())
	env = append(
		env,
		"GIT_CONFIG_GLOBAL="+os.DevNull,
		"GIT_CONFIG_SYSTEM="+os.DevNull,
		"GIT_CONFIG_NOSYSTEM=1",
		"GIT_NO_REPLACE_OBJECTS=1",
		"GIT_OPTIONAL_LOCKS=0",
		"GIT_TEMPLATE_DIR=",

View on GitHub (pinned to 71377f2769)

Solutions

  1. Install git (apt-get install -y git / brew install git) and rerun
  2. Fix PATH so the git binary's directory is included (check `which git`)
  3. If git is in a nonstandard location, add its dir to PATH before invoking bd

Example fix

// before (docker: no git)
bd worktree remove wt-x   # cannot find git executable
// after
RUN apt-get update && apt-get install -y git
bd worktree remove wt-x
Defensive patterns

Strategy: validation

Validate before calling

command -v git >/dev/null 2>&1 || { echo "git not on PATH"; exit 1; }

Try / catch

exe, err := exec.LookPath("git")
if err != nil {
    return fmt.Errorf("git required but not found: %w", err)
}

Prevention

When it happens

Trigger: Any `bd worktree remove` (prepareWorktreeRemoval) or the env-scrubbing test when `git` is not present in any PATH directory — git not installed, or PATH stripped/broken in the executing environment.

Common situations: Minimal Docker images without git; CI jobs with sanitized PATH; cron/systemd environments lacking the user's PATH; broken PATH typo (e.g. PATH=/usr/loca/bin).

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/9deac57c3d3459d9. Report an issue: GitHub.