abhigyanpatwari/GitNexus · error · GitNexusRcError

${source}: branch name must not contain a backtick (it would

Error message

${source}: branch name must not contain a backtick (it would break the generated Markdown).

What it means

Thrown by validateBranchName() when the branch name contains a backtick. Although git allows backticks in refnames, GitNexus embeds the branch inside a Markdown inline-code span in the generated AGENTS.md/CLAUDE.md regression example, where a backtick would close the span early and let the rest of the template render as instruction text — a prompt-injection risk. Rejecting it at this chokepoint covers all three input tiers (CLI flag, .gitnexusrc, auto-detect).

Source

Thrown at gitnexus/src/cli/analyze-config.ts:189

  if (/[~^:?*[\\]/.test(trimmed)) {
    throw new GitNexusRcError(
      `${source}: branch name contains characters not allowed in a git ref (~ ^ : ? * [ \\).`,
    );
  }
  if (trimmed.startsWith('-')) {
    throw new GitNexusRcError(`${source}: branch name must not start with "-".`);
  }
  if (trimmed.includes('..')) {
    throw new GitNexusRcError(`${source}: branch name must not contain "..".`);
  }
  // Git permits a backtick in a ref, but the branch is embedded inside a
  // Markdown inline-code span in the generated AGENTS.md/CLAUDE.md regression
  // example, where a backtick would close the span early and let the rest of
  // the template render as instruction text. Reject it at this single
  // chokepoint so all three tiers (CLI flag, .gitnexusrc, auto-detect via
  // sanitizeDetectedBranch) are covered (#1996 tri-review P1).
  if (trimmed.includes('`')) {
    throw new GitNexusRcError(
      `${source}: branch name must not contain a backtick (it would break the generated Markdown).`,
    );
  }
  return trimmed;
}

/**
 * Best-effort validation for an auto-detected branch (from git). Never throws —
 * returns `undefined` for anything unusable so the resolver falls back to the
 * next precedence tier.
 */
export function sanitizeDetectedBranch(value: string | null | undefined): string | undefined {
  if (!value) return undefined;
  try {
    return validateBranchName(value, 'detected branch');
  } catch {
    return undefined;
  }

View on GitHub (pinned to d540b00184)

Solutions

  1. Remove the backtick from the branch name.
  2. Rename the actual git branch if it contains a backtick, then re-run.

Example fix

# before
gitnexus analyze --default-branch "feature/`auth`"

# after
gitnexus analyze --default-branch "feature/auth"
Defensive patterns

Strategy: validation

Validate before calling

function assertNoBacktick(name: string): void {
  if (name.includes('`')) {
    throw new Error('branch name must not contain a backtick (would break generated Markdown)');
  }
}

Type guard

function hasNoBacktick(name: string): boolean {
  return typeof name === 'string' && !name.includes('`');
}

Prevention

When it happens

Trigger: Passing a branch name containing '`', e.g. a name auto-generated from a shell command substitution, or a paste that included a backtick.

Common situations: A branch name built from a templating script that wrapped a variable in backticks; copy-pasting from markdown where the name was inside a code span.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/b9cd3b29a0e9f1ae. Report an issue: GitHub.