badges/shields · error · InvalidParameter

no common ancestor

Error message

no common ancestor

What it means

The commit-status service compares commits between branches; when GitHub's API responds with NotFound whose JSON message starts with 'No common ancestor between', handle() rethrows it as InvalidParameter with 'no common ancestor'. GitHub cannot compute a comparison (ahead/behind/identical) for refs that share no merge-base. This is an input problem: the two requested refs are unrelated histories.

Source

Thrown at services/github/github-commit-status.service.js:74

        message: `not in ${branch}`,
        color: 'yellow',
      }
    }
  }

  async handle({ user, repo, branch, commit }) {
    let status
    try {
      ;({ status } = await this._requestJson({
        url: `/repos/${user}/${repo}/compare/${branch}...${commit}`,
        httpErrors: httpErrorsFor('commit or branch not found'),
        schema,
      }))
    } catch (e) {
      if (e instanceof NotFound) {
        const { message } = this._parseJson(e.buffer)
        if (message && message.startsWith('No common ancestor between')) {
          throw new InvalidParameter({ prettyMessage: 'no common ancestor' })
        }
      }
      throw e
    }

    const isInBranch = status === 'identical' || status === 'behind'
    return this.constructor.render({ isInBranch, branch })
  }
}

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Check the two refs actually share history: `git merge-base <ref1> <ref2>` locally; if it fails, the comparison is meaningless.
  2. Choose a base branch that is an ancestor of the head branch instead of an orphan branch.
  3. If gh-pages is orphaned, rebase/recreate it from the default branch or compare against the intended source branch.

Example fix

// before
/service/github/commit-status/user/repo/main/gh-pages.json
// after (compare against a related branch)
/service/github/commit-status/user/repo/main/feature-branch.json
Defensive patterns

Strategy: validation

Validate before calling

// ensure refs share history before comparing
import { execSync } from 'child_process';
try { execSync(`git merge-base origin/${base} ${head}`, { stdio: 'pipe' }); } catch { throw new Error('refs have no common ancestor'); }

Type guard

function isComparableRefs(refA, refB) {
  return typeof refA === 'string' && typeof refB === 'string' && refA !== refB && !refB.startsWith('gh-pages');
}

Try / catch

try {
  const status = await getCommitStatus({ base, head });
} catch (e) {
  if (e.prettyMessage === 'no common ancestor') {
    return { status: 'unrelated' }; // or prompt user to pick a related base
  } else throw e;
}

Prevention

When it happens

Trigger: Requesting github/commit-status for a base branch and head ref whose histories are disjoint, e.g. comparing an orphan branch (gh-pages created with --orphan, or a brand-new unrelated repo) against main, so GitHub replies 'No common ancestor between ...'.

Common situations: Comparing feature branches to an orphaned gh-pages branch; forks with rewritten history; comparing across repos with unrelated roots; a branch recreated from scratch with no shared commit history.

Related errors


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/2ef8bb833029f24a. Report an issue: GitHub.