mislav/hub · error

Aborted: head branch is the same as base ("%s") (use `-h <br

Error message

Aborted: head branch is the same as base ("%s")
(use `-h <branch>` to specify an explicit pull request head)

What it means

When opening a pull request, if the base project is the same as the head project and the base branch equals the tracked (head) branch name, the PR would have identical base and head, which GitHub rejects. hub aborts early and appends the hint to use '-h <branch>' to specify an explicit head. This index (35) captures the wrapped second error whose message is the hint line combined with the 'Aborted: head branch is the same as base' message via %s wrapping.

Source

Thrown at commands/pull_request.go:178

	}

	if flagPullRequestHead := args.Flag.Value("--head"); flagPullRequestHead != "" {
		headProject, head = parsePullRequestProject(headProject, flagPullRequestHead)
	}

	baseRemote, _ := localRepo.RemoteForProject(baseProject)
	if base == "" && baseRemote != nil {
		base = localRepo.DefaultBranch(baseRemote).ShortName()
	}

	if head == "" && trackedBranch != nil {
		if !trackedBranch.IsRemote() {
			// the current branch tracking another branch
			// pretend there's no upstream at all
			trackedBranch = nil
		} else {
			if baseProject.SameAs(headProject) && base == trackedBranch.ShortName() {
				e := fmt.Errorf(`Aborted: head branch is the same as base ("%s")`, base)
				e = fmt.Errorf("%s\n(use `-h <branch>` to specify an explicit pull request head)", e)
				utils.Check(e)
			}
		}
	}

	force := args.Flag.Bool("--force")
	flagPullRequestPush := args.Flag.Bool("--push")

	if head == "" {
		if trackedBranch == nil {
			utils.Check(currentBranchErr)
			if !force && !flagPullRequestPush {
				branchRemote, branchMerge, err := branchTrackingInformation(currentBranch)
				if err != nil || (baseRemote != nil && branchRemote == baseRemote.Name && branchMerge.ShortName() == base) {
					if localRepo.RemoteForBranch(currentBranch, host.User) == nil {
						err = fmt.Errorf("Aborted: the current branch seems not yet pushed to a remote")
						err = fmt.Errorf("%s\n(use `-p` to push the branch or `-f` to skip this check)", err)

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Create a feature branch and push it: git checkout -b my-feature && git push -u origin my-feature, then run hub pull-request
  2. Pass an explicit head: hub pull-request -h <owner>:<branch>
  3. Push to a fork and use the fork branch as head

Example fix

# before
$ git checkout main && hub pull-request
Aborted: head branch is the same as base ("main")
# after
$ git checkout -b my-feature && git push -u origin my-feature
$ hub pull-request
Defensive patterns

Strategy: validation

Validate before calling

branch=$(git rev-parse --abbrev-ref HEAD)
base=$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|origin/||')
[ "$branch" != "$base" ] || { echo "Refusing to PR from base branch $base"; exit 1; }

Prevention

When it happens

Trigger: Running 'hub pull-request' from a branch whose name equals the default/base branch (e.g. working directly on 'main') in the same repo, without specifying -h.

Common situations: Committing straight to the default branch and then trying to open a PR; forgetting to create/switch to a feature branch; automating PR creation on the wrong branch.

Related errors


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