{"record":{"id":"cc89a36f3a521a25","repo":"mislav/hub","slug":"s-use-h-branch-to-specify-an-explicit-pull","errorCode":null,"errorMessage":"%s\n(use `-h <branch>` to specify an explicit pull request head)","messagePattern":"(.+?)\n\\(use `-h <branch>` to specify an explicit pull request head\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/pull_request.go","lineNumber":179,"sourceCode":"\n\tif flagPullRequestHead := args.Flag.Value(\"--head\"); flagPullRequestHead != \"\" {\n\t\theadProject, head = parsePullRequestProject(headProject, flagPullRequestHead)\n\t}\n\n\tbaseRemote, _ := localRepo.RemoteForProject(baseProject)\n\tif base == \"\" && baseRemote != nil {\n\t\tbase = localRepo.DefaultBranch(baseRemote).ShortName()\n\t}\n\n\tif head == \"\" && trackedBranch != nil {\n\t\tif !trackedBranch.IsRemote() {\n\t\t\t// the current branch tracking another branch\n\t\t\t// pretend there's no upstream at all\n\t\t\ttrackedBranch = nil\n\t\t} else {\n\t\t\tif baseProject.SameAs(headProject) && base == trackedBranch.ShortName() {\n\t\t\t\te := fmt.Errorf(`Aborted: head branch is the same as base (\"%s\")`, base)\n\t\t\t\te = fmt.Errorf(\"%s\\n(use `-h <branch>` to specify an explicit pull request head)\", e)\n\t\t\t\tutils.Check(e)\n\t\t\t}\n\t\t}\n\t}\n\n\tforce := args.Flag.Bool(\"--force\")\n\tflagPullRequestPush := args.Flag.Bool(\"--push\")\n\n\tif head == \"\" {\n\t\tif trackedBranch == nil {\n\t\t\tutils.Check(currentBranchErr)\n\t\t\tif !force && !flagPullRequestPush {\n\t\t\t\tbranchRemote, branchMerge, err := branchTrackingInformation(currentBranch)\n\t\t\t\tif err != nil || (baseRemote != nil && branchRemote == baseRemote.Name && branchMerge.ShortName() == base) {\n\t\t\t\t\tif localRepo.RemoteForBranch(currentBranch, host.User) == nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"Aborted: the current branch seems not yet pushed to a remote\")\n\t\t\t\t\t\terr = fmt.Errorf(\"%s\\n(use `-p` to push the branch or `-f` to skip this check)\", err)\n\t\t\t\t\t\tutils.Check(err)","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/pull_request.go#L161-L197","documentation":"Same abort path as the 'head branch is the same as base' error: pullRequest wraps the original error with fmt.Errorf(\"%s\\n(use `-h <branch>` ...)\") and passes it to utils.Check. This index records the wrapping error whose format string is the hint suffix, printed with the base-branch message above it.","triggerScenarios":"Identical to error 34: baseProject.SameAs(headProject) && base == trackedBranch.ShortName() when creating a PR — same-repo PR where the head branch name equals the base branch name and -h was not given.","commonSituations":"Opening a PR from the default branch; scripted PR creation running on 'main' in CI.","solutions":["Run the PR from a differently-named pushed branch","Use -h <branch> (or <owner>:<branch> for forks) to give an explicit head","Automations should assert the current branch differs from the base before invoking hub"],"exampleFix":"# before\nhub pull-request -m \"msg\"           # run on main\n# after\nhub pull-request -m \"msg\" -h my-feature","handlingStrategy":"validation","validationCode":"branch=$(git rev-parse --abbrev-ref HEAD)\n[ \"$branch\" != \"$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|origin/||')\" ] || exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Same as the base error: work on feature branches, not the base branch","Parse the two-line aborted message in automation and act on the first line"],"tags":["git","pull-request","branch","hub-cli"],"backgroundTag":"head-equals-base-branch","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}