{"record":{"id":"286071f967efb820","repo":"gastownhall/beads","slug":"failed-to-get-current-branch-w","errorCode":null,"errorMessage":"failed to get current branch: %w","messagePattern":"failed to get current branch: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init_team.go","lineNumber":40,"sourceCode":"\t\tctx = context.Background()\n\t}\n\treader := bufio.NewReader(os.Stdin)\n\n\t// Step 1: Check if we're in a git repository\n\tfmt.Printf(\"%s Detecting git repository setup...\\n\", ui.RenderAccent(\"▶\"))\n\n\tif !isGitRepo() {\n\t\tfmt.Printf(\"%s Not in a git repository\\n\", ui.RenderWarn(\"⚠\"))\n\t\tfmt.Println(\"\\n  Initialize git first:\")\n\t\tfmt.Println(\"  git init\")\n\t\tfmt.Println()\n\t\treturn fmt.Errorf(\"not in a git repository\")\n\t}\n\n\t// Get current branch\n\tcurrentBranch, err := getGitBranch()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current branch: %w\", err)\n\t}\n\n\tfmt.Printf(\"%s Current branch: %s\\n\", ui.RenderPass(\"✓\"), currentBranch)\n\n\t// Step 2: Check for protected main branch\n\tfmt.Printf(\"\\n%s Checking branch configuration...\\n\", ui.RenderAccent(\"▶\"))\n\n\tfmt.Println(\"\\nIs your main branch protected (prevents direct commits)?\")\n\tfmt.Println(\"  GitHub: Settings → Branches → Branch protection rules\")\n\tfmt.Println(\"  GitLab: Settings → Repository → Protected branches\")\n\tfmt.Print(\"\\nProtected main branch? [y/N]: \")\n\n\tresponse, err := readLineWithContext(ctx, reader, os.Stdin)\n\tif err != nil {\n\t\tif isCanceled(err) {\n\t\t\treturn err\n\t\t}\n\t\tresponse = \"\"","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init_team.go#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (repo with unborn HEAD)\n$ bd init --team\nfailed to get current branch: fatal: ambiguous argument 'HEAD'...\n// after\n$ git commit --allow-empty -m \"initial commit\"\n$ bd init --team","handlingStrategy":"validation","validationCode":"if !isGitRepo() { return errors.New(\"not in a git repository\") }\nout, err := exec.Command(\"git\", \"rev-parse\", \"--abbrev-ref\", \"HEAD\").Output()\nif err != nil { return fmt.Errorf(\"git branch detection failed, commit first: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err := runTeamWizard(ctx, st); err != nil {\n    var ge *exec.ExitError\n    if errors.As(err, &ge) { fmt.Fprintln(os.Stderr, \"git failure:\", string(ge.Stderr)) }\n    os.Exit(1)\n}","preventionTips":["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"],"tags":["git","init","wizard","branch"],"backgroundTag":"git-branch-detection-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}