{"record":{"id":"3438eb91409db888","repo":"mislav/hub","slug":"the-branch-to-compare-s-is-the-default-branch","errorCode":null,"errorMessage":"the branch to compare '%s' is the default branch","messagePattern":"the branch to compare '(.+?)' is the default branch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/compare.go","lineNumber":101,"sourceCode":"\t\t\tutils.Check(command.UsageError(err.Error()))\n\t\t}\n\n\t\tvar remoteBranch *github.Branch\n\t\tvar remoteProject *github.Project\n\n\t\tremoteBranch, remoteProject, err = findPushTarget(currentBranch)\n\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)","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/compare.go#L83-L119","documentation":"In commands/compare.go compare, when the remote branch belongs to the same project as the main project and no --base flag was given, comparing the master (default) branch against itself is meaningless, so the command aborts with \"the branch to compare '%s' is the default branch\".","triggerScenarios":"Running `hub compare` (or `hub compare master`) while the resolved push target of the current branch is the master/default branch of the same repository, with flagCompareBase empty and remoteBranch.IsMaster() true.","commonSituations":"Checking out master and running `hub compare` expecting a diff; forgetting to switch to a feature branch; a push target that still points at master after branching locally.","solutions":["Switch to the feature branch you want to compare: `git checkout <feature>` then `hub compare`.","Compare against the default branch explicitly: `hub compare <feature>` from another branch.","Use `--base` to give a different base: `hub compare --base master <feature>`."],"exampleFix":"// before\ngit checkout master\nhub compare   // the branch to compare 'master' is the default branch\n// after\ngit checkout feature-x\nhub compare","handlingStrategy":"validation","validationCode":"# refuse to run compare while on the default branch\nbranch=$(git rev-parse --abbrev-ref HEAD)\n[ \"$branch\" = \"master\" ] && { echo \"switch to a feature branch first\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if remoteProject.SameAs(mainProject) && flagCompareBase == \"\" && remoteBranch.IsMaster() {\n    return fmt.Errorf(\"compare a non-default branch instead\")\n}","preventionTips":["Never run bare `hub compare` from the default branch","Checkout the feature branch before comparing","Use --base with an explicit non-default target when needed"],"tags":["git","cli","branch","compare"],"backgroundTag":"compare-branch-same-as-default","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}