mislav/hub · error
the branch to compare '%s' is the default branch
Error message
the branch to compare '%s' is the default branch
What it means
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".
Source
Thrown at commands/compare.go:101
utils.Check(command.UsageError(err.Error()))
}
var remoteBranch *github.Branch
var remoteProject *github.Project
remoteBranch, remoteProject, err = findPushTarget(currentBranch)
if err != nil {
if remoteProject, err = deducePushTarget(currentBranch, host.User); err == nil {
remoteBranch = currentBranch
} else {
utils.Check(fmt.Errorf("the current branch '%s' doesn't seem pushed to a remote", currentBranch.ShortName()))
}
}
r = remoteBranch.ShortName()
if remoteProject.SameAs(mainProject) {
if flagCompareBase == "" && remoteBranch.IsMaster() {
utils.Check(fmt.Errorf("the branch to compare '%s' is the default branch", remoteBranch.ShortName()))
}
} else {
r = fmt.Sprintf("%s:%s", remoteProject.Owner, r)
}
if flagCompareBase == r {
utils.Check(fmt.Errorf("the branch to compare '%s' is the same as --base", r))
} else if flagCompareBase != "" {
r = fmt.Sprintf("%s...%s", flagCompareBase, r)
}
} else {
if flagCompareBase != "" {
utils.Check(command.UsageError(""))
} else {
r = parseCompareRange(args.RemoveParam(args.ParamsSize() - 1))
if !args.IsParamsEmpty() {
owner := args.RemoveParam(args.ParamsSize() - 1)
mainProject = github.NewProject(owner, mainProject.Name, mainProject.Host)View on GitHub (pinned to 5c547ed804)
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>`.
Example fix
// before git checkout master hub compare // the branch to compare 'master' is the default branch // after git checkout feature-x hub compare
Defensive patterns
Strategy: validation
Validate before calling
# refuse to run compare while on the default branch
branch=$(git rev-parse --abbrev-ref HEAD)
[ "$branch" = "master" ] && { echo "switch to a feature branch first"; exit 1; } Try / catch
if remoteProject.SameAs(mainProject) && flagCompareBase == "" && remoteBranch.IsMaster() {
return fmt.Errorf("compare a non-default branch instead")
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- the branch to compare '%s' is the same as --base
- the current branch '%s' doesn't seem pushed to a remote
- Aborted: no revision could be determined from '%s'
- Error: %s/%s doesn't have a wiki
- 'create' must be run from inside a git repository
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/3438eb91409db888.
Report an issue: GitHub.