gastownhall/beads · error
not a git repository
Error message
not a git repository
What it means
GitHooks installs bd's git hooks via the `bd hooks install` subprocess, but first verifies the target path is a git repository by running `git rev-parse --git-dir` with cmd.Dir set to path. If that command fails (non-zero exit / git not resolvable), the plain error "not a git repository" is returned and no hooks are installed.
Source
Thrown at cmd/bd/doctor/fix/hooks.go:606
}
return strings.Join(names, ", ")
}
// GitHooks fixes missing or broken git hooks by calling bd hooks install.
// If external hook managers are detected (lefthook, husky, etc.), it uses
// --chain to preserve existing hooks instead of overwriting them.
func GitHooks(path string) error {
// Validate workspace
if err := validateBeadsWorkspace(path); err != nil {
return err
}
// Check if we're in a git repository using git rev-parse
// This handles worktrees where .git is a file, not a directory
checkCmd := exec.Command("git", "rev-parse", "--git-dir")
checkCmd.Dir = path
if err := checkCmd.Run(); err != nil {
return fmt.Errorf("not a git repository")
}
// Detect external hook managers
externalManagers := DetectExternalHookManagers(path)
// Get bd binary path
bdBinary, err := getBdBinary()
if err != nil {
return err
}
// Build command arguments
// Use --force to cleanly replace outdated hooks without creating backups (GH#1466)
args := []string{"hooks", "install", "--force"}
// If external hook managers detected, use --chain to preserve them
if len(externalManagers) > 0 {
args = append(args, "--chain")View on GitHub (pinned to 71377f2769)
Solutions
- Run the command from inside a valid git repository (cd to the repo root or a tracked subdirectory)
- Verify with `git rev-parse --git-dir` yourself in the target path
- If it's a worktree, repair the .git file link (git worktree repair); ensure git is installed and on PATH
Example fix
// before
err := fix.G-hooks(path) // not a git repository
// after: guard before calling
if err := exec.Command("git", "-C", path, "rev-parse", "--git-dir").Run(); err != nil {
return fmt.Errorf("skipping hooks: %s is not a git repo", path)
} Defensive patterns
Strategy: validation
Validate before calling
cmd := exec.Command("git", "-C", path, "rev-parse", "--git-dir")
if err := cmd.Run(); err != nil {
return fmt.Errorf("%s is not a git repository, skipping hooks install", path)
} Try / catch
if err := fix.GitHooks(path, bdBinary); err != nil {
if err.Error() == "not a git repository" {
log.Printf("skipping hooks: %s has no git work tree", path)
return nil // non-fatal for doctor runs outside repos
}
return err
} Prevention
- Always run doctor/hook fixes from inside a git work tree
- Verify `git rev-parse --git-dir` succeeds in the target path first
- Ensure git is installed and on PATH in containers/CI images
- Repair broken worktrees with `git worktree repair`
When it happens
Trigger: Calling GitHooks (via bd doctor hook fixes) on a directory that is not inside a git work tree: a plain folder, a bare repo without a work tree at that path, a deleted/invalid .git, or git not on PATH so exec fails.
Common situations: Running `bd doctor` in a subdirectory outside any repo; CI checkouts using shallow/submodule setups with broken .git; worktrees whose .git file points at a missing branch dir; PATH missing git in containers.
Related errors
- failed to install hooks: %w
- unable to determine home directory: %w
- bd binary not found in PATH: %w
- git config --unset core.hooksPath failed: %w (output: %s)
- reading git log: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/ec08fd6b9d62f114.
Report an issue: GitHub.