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

  1. Create/switch to a branch: git checkout -b <name>
  2. Switch back to a normal branch: git checkout main
  3. If from a detached rebase, finish or abort: git rebase --continue / --abort
  4. 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

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


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/af128128ef6ef939. Report an issue: GitHub.