gastownhall/beads · error
not in a git repository
Error message
not in a git repository
What it means
configureSharedHooksPath sets core.hooksPath to <repoRoot>/.beads-hooks and needs a repository root to anchor it (git resolves relative hooks paths against the work tree root, hence the absolute path). It tries git.GetMainRepoRoot() then git.GetRepoRoot(); when both are empty it fails with `not in a git repository`.
Source
Thrown at cmd/bd/hooks.go:1288
// v9: `. "$(dirname "$0")/h"` (or with `--` / single quotes).
// Require both `dirname` and a trailing `/h"` or `/h'` to avoid matching
// unrelated sourcing of files that happen to end in "h".
if strings.Contains(line, "dirname") && (strings.HasSuffix(line, `/h"`) || strings.HasSuffix(line, `/h'`) || strings.HasSuffix(line, "/h")) {
return true
}
return false
}
func configureSharedHooksPath() error {
// Set git config core.hooksPath to an absolute path pointing to .beads-hooks.
// Using an absolute path is critical for git worktrees (GH#2414):
// git resolves relative core.hooksPath relative to the working tree root.
repoRoot, _ := git.GetMainRepoRoot()
if repoRoot == "" {
repoRoot = git.GetRepoRoot()
}
if repoRoot == "" {
return fmt.Errorf("not in a git repository")
}
absHooksPath := filepath.Join(repoRoot, ".beads-hooks")
cmd := exec.Command("git", "config", "core.hooksPath", absHooksPath)
cmd.Dir = repoRoot
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("git config failed: %w (output: %s)", err, string(output))
}
return nil
}
func configureBeadsHooksPath() error {
// Set git config core.hooksPath to an absolute path pointing to .beads/hooks.
// Using an absolute path is critical for git worktrees (GH#2414):
// git resolves relative core.hooksPath relative to the working tree root,
// so in a worktree ".beads/hooks" would resolve to <worktree>/.beads/hooks/
// which doesn't exist — the hooks live in the main repo's .beads/hooks/.
repoRoot, _ := git.GetMainRepoRoot()
if repoRoot == "" {View on GitHub (pinned to 71377f2769)
Solutions
- Run `git init` if the directory should be a repository, then re-run the bd command
- cd into the actual repository root and re-run `bd hooks install --shared`
- Verify `git rev-parse --show-toplevel` succeeds from your current directory
- If in CI without .git, fetch the full checkout (git fetch / clone) before installing hooks
Example fix
// before $ cd /tmp/proj-src && bd hooks install --shared not in a git repository // after $ git init && bd hooks install --shared
Defensive patterns
Strategy: validation
Validate before calling
git rev-parse --show-toplevel >/dev/null 2>&1 && echo ok || echo 'not a git repository — run git init or cd into the repo'
Try / catch
if err := installHooksWithOptions(names, false, true, false, false); err != nil { if strings.Contains(err.Error(), "not in a git repository") { /* run git init or change directory, then retry */ } } Prevention
- Confirm `git rev-parse --show-toplevel` works before shared hook installs
- Run `git init` before bd setup in brand-new projects
- In CI, use a full git clone (not an exported tarball) when installing hooks
When it happens
Trigger: installHooksWithOptions (shared mode) calls configureSharedHooksPath from a directory where git cannot find a work tree — no .git anywhere up the tree, GIT_DIR pointing nowhere, or an uninitialized repo.
Common situations: Running `bd hooks install --shared` in a temp directory or home dir outside any repo; running before `git init`; CI steps that download sources without the .git directory.
Related errors
- failed to configure git hooks path: %w
- not in a git repository
- not a git repository
- not a git repository: %w
- not a git repository
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/ea68ac3d5b17ddc6.
Report an issue: GitHub.