gastownhall/beads · error
failed to get current branch: %w
Error message
failed to get current branch: %w
What it means
During `bd init --team`'s wizard (runTeamWizard), after confirming the working directory is a git repo, bd calls getGitBranch() to learn the current branch name. If that command fails (git errors, detached/unparseable output), the error is wrapped as 'failed to get current branch: %w' and aborts the wizard. It indicates git itself could not report the current branch.
Source
Thrown at cmd/bd/init_team.go:40
ctx = context.Background()
}
reader := bufio.NewReader(os.Stdin)
// Step 1: Check if we're in a git repository
fmt.Printf("%s Detecting git repository setup...\n", ui.RenderAccent("▶"))
if !isGitRepo() {
fmt.Printf("%s Not in a git repository\n", ui.RenderWarn("⚠"))
fmt.Println("\n Initialize git first:")
fmt.Println(" git init")
fmt.Println()
return fmt.Errorf("not in a git repository")
}
// Get current branch
currentBranch, err := getGitBranch()
if err != nil {
return fmt.Errorf("failed to get current branch: %w", err)
}
fmt.Printf("%s Current branch: %s\n", ui.RenderPass("✓"), currentBranch)
// Step 2: Check for protected main branch
fmt.Printf("\n%s Checking branch configuration...\n", ui.RenderAccent("▶"))
fmt.Println("\nIs your main branch protected (prevents direct commits)?")
fmt.Println(" GitHub: Settings → Branches → Branch protection rules")
fmt.Println(" GitLab: Settings → Repository → Protected branches")
fmt.Print("\nProtected main branch? [y/N]: ")
response, err := readLineWithContext(ctx, reader, os.Stdin)
if err != nil {
if isCanceled(err) {
return err
}
response = ""View on GitHub (pinned to 71377f2769)
Solutions
- Make at least one commit (`git commit --allow-empty -m init`) so HEAD resolves, then re-run `bd init --team`
- Run `git rev-parse --abbrev-ref HEAD` manually to see the underlying git error
- Verify git is installed and the .git directory is not corrupted (`git status`)
- Check file permissions on .git/HEAD
Example fix
// before (repo with unborn HEAD) $ bd init --team failed to get current branch: fatal: ambiguous argument 'HEAD'... // after $ git commit --allow-empty -m "initial commit" $ bd init --team
Defensive patterns
Strategy: validation
Validate before calling
if !isGitRepo() { return errors.New("not in a git repository") }
out, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
if err != nil { return fmt.Errorf("git branch detection failed, commit first: %w", err) } Try / catch
if err := runTeamWizard(ctx, st); err != nil {
var ge *exec.ExitError
if errors.As(err, &ge) { fmt.Fprintln(os.Stderr, "git failure:", string(ge.Stderr)) }
os.Exit(1)
} Prevention
- Always make an initial commit before running bd init --team so HEAD exists
- Run `git rev-parse --abbrev-ref HEAD` as a pre-check in scripts
- Avoid running bd inside bare repositories
When it happens
Trigger: Running `bd init --team` in a directory that is a git repo but where `git rev-parse --abbrev-ref HEAD` fails: bare repository, repo with no commits yet (unborn HEAD), corrupted .git, or git not functioning in the environment.
Common situations: Freshly `git init`-ed repo with zero commits; running bd inside a bare clone; broken or partial .git directory; CI containers with unusual git configs; permission problems reading .git/HEAD.
Related errors
- failed to initialize git repository: %v %s
- running contributor wizard: %v
- running team wizard: %v
- not in a git repository
- merge branch %s: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/286071f967efb820.
Report an issue: GitHub.