{"record":{"id":"af128128ef6ef939","repo":"mislav/hub","slug":"aborted-not-currently-on-any-branch","errorCode":null,"errorMessage":"Aborted: not currently on any branch.","messagePattern":"Aborted: not currently on any branch\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"github/localrepo.go","lineNumber":99,"sourceCode":"\t\tname := names[i]\n\t\tif remote, ok := remotesMap[name]; ok {\n\t\t\tremotes = append(remotes, remote)\n\t\t\tdelete(remotesMap, name)\n\t\t}\n\t}\n\n\t// anything other than names has higher priority\n\tfor _, remote := range remotesMap {\n\t\tremotes = append([]Remote{remote}, remotes...)\n\t}\n\n\treturn\n}\n\nfunc (r *GitHubRepo) CurrentBranch() (branch *Branch, err error) {\n\thead, err := git.Head()\n\tif err != nil {\n\t\terr = fmt.Errorf(\"Aborted: not currently on any branch.\")\n\t\treturn\n\t}\n\n\tbranch = &Branch{r, head}\n\treturn\n}\n\nfunc (r *GitHubRepo) MasterBranch() *Branch {\n\tif remote, err := r.MainRemote(); err == nil {\n\t\treturn r.DefaultBranch(remote)\n\t}\n\treturn r.DefaultBranch(nil)\n}\n\nfunc (r *GitHubRepo) DefaultBranch(remote *Remote) *Branch {\n\tb := Branch{\n\t\tRepo: r,\n\t\tName: \"refs/heads/master\",","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/github/localrepo.go#L81-L117","documentation":"CurrentBranch() calls git.Head(), which resolves HEAD to a branch. When HEAD is detached (or unborn on an empty repo) Head() fails and the error is replaced with this message. The library aborts because operations like finding the current PR require knowing the checked-out branch.","triggerScenarios":"Calling CurrentBranch() (via findCurrentPullRequest, RemoteBranchAndProject, UpstreamProject) while HEAD points at a commit instead of a branch: after `git checkout <sha>`, a failed branch checkout, rebase in detached state, or in a freshly `git init`ed repo with no commits.","commonSituations":"CI checkouts that pin a commit SHA; debugging with `git checkout <tag>`; a rebase conflict left the repo detached; brand-new repo before first commit (unborn HEAD); tools that detach HEAD automatically.","solutions":["Create/switch to a branch: git checkout -b <name>","Switch back to a normal branch: git checkout main","If from a detached rebase, finish or abort: git rebase --continue / --abort","In an empty repo, make the first commit so HEAD becomes a branch"],"exampleFix":"// before (detached HEAD)\ngit checkout a1b2c3d\n// after\ngit checkout -b fix/issue-42 a1b2c3d","handlingStrategy":"validation","validationCode":"out, _ := exec.Command(\"git\", \"symbolic-ref\", \"-q\", \"--short\", \"HEAD\").Output()\nif len(strings.TrimSpace(string(out))) == 0 {\n    // HEAD is detached or unborn; create/switch to a branch first\n}","typeGuard":null,"tryCatchPattern":"branch, err := repo.CurrentBranch()\nif err != nil {\n    if strings.Contains(err.Error(), \"not currently on any branch\") {\n        return fmt.Errorf(\"detached HEAD: create a branch with git checkout -b <name>\")\n    }\n    return err\n}","preventionTips":["Avoid `git checkout <sha|tag>`; prefer `git switch -c <branch> <sha>`","In CI, use a full branch checkout instead of pinning SHAs","Finish or abort interrupted rebases before running hub commands","Check `git status` shows 'On branch <x>' before branch-dependent calls"],"tags":["git","detached-head","branch"],"backgroundTag":"detached-head","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}