abhigyanpatwari/GitNexus · error

--branch " " does not match the checked-out branch " "…

Error message

--branch "${options.branch}" does not match the checked-out branch "${checkedOutBranch}". Check out "${options.branch}" before indexing it, or omit --branch to index the current branch.

What it means

Error "--branch "${options.branch}" does not match the checked-out branch "${checkedOutBranch}". Check out "${options.branch}" before indexing it, or omit --branch to index the current branch." thrown in abhigyanpatwari/GitNexus.

When it happens

Trigger: Thrown at gitnexus/src/core/run-analyze.ts:967 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of abhigyanpatwari/GitNexus@ac9a4e9abd (2026-08-20). Data as JSON: /api/errors/463824457b95c5f1. Report an issue: GitHub.

Appendix: source

Thrown at gitnexus/src/core/run-analyze.ts:1084

  const storagePath = await requireStoragePath(
    repoPath,
    options.force ? ANALYZE_FORCE_STORAGE_REQUIREMENTS : ANALYZE_STORAGE_REQUIREMENTS,
  );
  const repoHasGit = hasGitDir(repoPath);
  const currentCommit = repoHasGit ? getCurrentCommit(repoPath) : '';
  // Normalize the auto-detected branch the same way an explicit `--branch` is
  // validated (#2106 R1): a git ref the branch-name rules forbid becomes `null`
  // → the flat slot, matching that a later `--branch <that-ref>` query would
  // also be rejected. A normal ref round-trips index-time/query-time labels.
  const checkedOutBranch = repoHasGit
    ? (sanitizeDetectedBranch(getCurrentBranch(repoPath)) ?? null)
    : null;
  // Analyze indexes the working tree, not an arbitrary ref. An explicit
  // `--branch X` while a DIFFERENT branch Y is checked out would write Y's
  // content into X's slot, corrupting X (#2106). Refuse the mismatch. Detached
  // HEAD / non-git (checkedOutBranch === null) still allow an explicit label.
  if (options.branch && checkedOutBranch && options.branch !== checkedOutBranch) {
    throw new Error(
      `--branch "${options.branch}" does not match the checked-out branch "${checkedOutBranch}". ` +
        `Check out "${options.branch}" before indexing it, or omit --branch to index the current branch.`,
    );
  }
  const branchLabel = options.branch ?? checkedOutBranch;
  const placement = options.branch
    ? await resolveBranchPlacement(repoPath, branchLabel, storagePath)
    : {};
  const { lbugPath, metaPath } = getStoragePaths(repoPath, placement.branch, storagePath);
  return {
    storagePath,
    repoHasGit,
    currentCommit,
    checkedOutBranch,
    branchLabel,
    placement,
    lbugPath,
    metaPath,

View on GitHub (pinned to ac9a4e9abd)