{"record":{"id":"f337e57bcb85c591","repo":"mislav/hub","slug":"the-branch-to-compare-s-is-the-same-as-base","errorCode":null,"errorMessage":"the branch to compare '%s' is the same as --base","messagePattern":"the branch to compare '(.+?)' is the same as --base","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/compare.go","lineNumber":108,"sourceCode":"\t\tif err != nil {\n\t\t\tif remoteProject, err = deducePushTarget(currentBranch, host.User); err == nil {\n\t\t\t\tremoteBranch = currentBranch\n\t\t\t} else {\n\t\t\t\tutils.Check(fmt.Errorf(\"the current branch '%s' doesn't seem pushed to a remote\", currentBranch.ShortName()))\n\t\t\t}\n\t\t}\n\n\t\tr = remoteBranch.ShortName()\n\t\tif remoteProject.SameAs(mainProject) {\n\t\t\tif flagCompareBase == \"\" && remoteBranch.IsMaster() {\n\t\t\t\tutils.Check(fmt.Errorf(\"the branch to compare '%s' is the default branch\", remoteBranch.ShortName()))\n\t\t\t}\n\t\t} else {\n\t\t\tr = fmt.Sprintf(\"%s:%s\", remoteProject.Owner, r)\n\t\t}\n\n\t\tif flagCompareBase == r {\n\t\t\tutils.Check(fmt.Errorf(\"the branch to compare '%s' is the same as --base\", r))\n\t\t} else if flagCompareBase != \"\" {\n\t\t\tr = fmt.Sprintf(\"%s...%s\", flagCompareBase, r)\n\t\t}\n\t} else {\n\t\tif flagCompareBase != \"\" {\n\t\t\tutils.Check(command.UsageError(\"\"))\n\t\t} else {\n\t\t\tr = parseCompareRange(args.RemoveParam(args.ParamsSize() - 1))\n\t\t\tif !args.IsParamsEmpty() {\n\t\t\t\towner := args.RemoveParam(args.ParamsSize() - 1)\n\t\t\t\tmainProject = github.NewProject(owner, mainProject.Name, mainProject.Host)\n\t\t\t}\n\t\t}\n\t}\n\n\turl := mainProject.WebURL(\"\", \"\", \"compare/\"+rangeQueryEscape(r))\n\n\targs.NoForward()","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/compare.go#L90-L126","documentation":"In commands/compare.go compare, after resolving the target branch r (possibly namespaced as owner:branch), it checks whether r equals the --base value. Identical base and compare branches would produce an empty range, so the command fails with \"the branch to compare '%s' is the same as --base\".","triggerScenarios":"Running `hub compare --base X X` (or a branch that resolves to the same owner:branch string as --base, e.g. same branch name in the same project).","commonSituations":"Scripting the command with a variable holding the branch name that also got assigned to --base; passing the branch twice by habit; forgetting that bare names on the same repo resolve identically to the --base value.","solutions":["Pass a different branch as the compare target than the one given to --base.","Remove `--base` if you intended the default comparison against the default branch.","If you meant the three-dot form, choose a distinct base (e.g. --base master with target feature)."],"exampleFix":"// before\nhub compare --base feature-x feature-x   // same as --base\n// after\nhub compare --base master feature-x","handlingStrategy":"validation","validationCode":"// ensure base and target differ before invoking\nif flagCompareBase != \"\" && flagCompareBase == targetBranch {\n    return fmt.Errorf(\"--base must differ from the branch to compare\")\n}","typeGuard":null,"tryCatchPattern":"if flagCompareBase == r {\n    return fmt.Errorf(\"base (%s) equals compare target; pick a different base\", r)\n}","preventionTips":["In scripts, assert the two branch variables are not equal","Remember namespaced targets (owner:branch) compare as full strings","Review generated hub compare commands in CI logs"],"tags":["git","cli","branch","compare"],"backgroundTag":"compare-base-equals-target","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}