{"record":{"id":"c415361c49fdc1a8","repo":"mislav/hub","slug":"aborted-head-branch-is-the-same-as-base-s-u","errorCode":null,"errorMessage":"Aborted: head branch is the same as base (\"%s\")\n(use `-h <branch>` to specify an explicit pull request head)","messagePattern":"Aborted: head branch is the same as base \\(\"(.+?)\"\\)\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":178,"sourceCode":"\t}\n\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)","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/pull_request.go#L160-L196","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create a feature branch and push it: git checkout -b my-feature && git push -u origin my-feature, then run hub pull-request","Pass an explicit head: hub pull-request -h <owner>:<branch>","Push to a fork and use the fork branch as head"],"exampleFix":"# before\n$ git checkout main && hub pull-request\nAborted: head branch is the same as base (\"main\")\n# after\n$ git checkout -b my-feature && git push -u origin my-feature\n$ hub pull-request","handlingStrategy":"validation","validationCode":"branch=$(git rev-parse --abbrev-ref HEAD)\nbase=$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|origin/||')\n[ \"$branch\" != \"$base\" ] || { echo \"Refusing to PR from base branch $base\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never open PRs from the default branch; branch first","Assert current branch != default branch in CI before hub pull-request","Use -h to name an explicit head when automating"],"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"}