mislav/hub · error
Aborted: not currently on any branch.
Error message
Aborted: not currently on any branch.
What it means
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.
Source
Thrown at github/localrepo.go:99
name := names[i]
if remote, ok := remotesMap[name]; ok {
remotes = append(remotes, remote)
delete(remotesMap, name)
}
}
// anything other than names has higher priority
for _, remote := range remotesMap {
remotes = append([]Remote{remote}, remotes...)
}
return
}
func (r *GitHubRepo) CurrentBranch() (branch *Branch, err error) {
head, err := git.Head()
if err != nil {
err = fmt.Errorf("Aborted: not currently on any branch.")
return
}
branch = &Branch{r, head}
return
}
func (r *GitHubRepo) MasterBranch() *Branch {
if remote, err := r.MainRemote(); err == nil {
return r.DefaultBranch(remote)
}
return r.DefaultBranch(nil)
}
func (r *GitHubRepo) DefaultBranch(remote *Remote) *Branch {
b := Branch{
Repo: r,
Name: "refs/heads/master",View on GitHub (pinned to 5c547ed804)
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
Example fix
// before (detached HEAD) git checkout a1b2c3d // after git checkout -b fix/issue-42 a1b2c3d
Defensive patterns
Strategy: validation
Validate before calling
out, _ := exec.Command("git", "symbolic-ref", "-q", "--short", "HEAD").Output()
if len(strings.TrimSpace(string(out))) == 0 {
// HEAD is detached or unborn; create/switch to a branch first
} Try / catch
branch, err := repo.CurrentBranch()
if err != nil {
if strings.Contains(err.Error(), "not currently on any branch") {
return fmt.Errorf("detached HEAD: create a branch with git checkout -b <name>")
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- the current branch '%s' doesn't seem pushed to a remote
- the branch to compare '%s' is the default branch
- the branch to compare '%s' is the same as --base
- Aborted: head branch is the same as base ("%s") (use `-h <br
- %s (use `-h <branch>` to specify an explicit pull request he
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/af128128ef6ef939.
Report an issue: GitHub.