{"record":{"id":"0f2e5d2c3a80dec1","repo":"can1357/oh-my-pi","slug":"local-branch-localbranch-does-not-exist","errorCode":null,"errorMessage":"local branch ${localBranch} does not exist","messagePattern":"local branch (.+?) does not exist","errorType":"validation","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/gh-pr-checkout.ts","lineNumber":529,"sourceCode":"\t\tbranch: outcome.localBranch,\n\t\tworktreePath: outcome.worktreePath,\n\t\tremote: outcome.remoteName,\n\t\tremoteBranch: outcome.headRefName,\n\t\treused: outcome.reused,\n\t};\n}\n\nexport async function executePrPush(\n\tsession: ToolSession,\n\tparams: GithubInput,\n\tsignal: AbortSignal | undefined,\n): Promise<AgentToolResult<GhToolDetails>> {\n\tconst repoRoot = await requireGitRepoRoot(session.cwd, signal);\n\tconst repository = vcs.requireGit(repoRoot);\n\tconst localBranch = normalizeOptionalString(params.branch) ?? (await requireCurrentGitBranch(repoRoot, signal));\n\tconst refExists = await repository.refExists(toLocalBranchRef(localBranch), signal);\n\tif (!refExists) {\n\t\tthrow new ToolError(`local branch ${localBranch} does not exist`);\n\t}\n\n\tconst target = await resolvePrBranchPushTarget(repoRoot, localBranch, signal);\n\tconst currentBranch = await repository.currentBranch(signal);\n\tconst sourceRef = currentBranch === localBranch ? \"HEAD\" : toLocalBranchRef(localBranch);\n\tconst refspec = `${sourceRef}:refs/heads/${target.remoteBranch}`;\n\tawait repository.push(\n\t\t{\n\t\t\tforceWithLease: params.forceWithLease,\n\t\t\trefspec,\n\t\t\tremote: target.remoteName,\n\t\t},\n\t\tsignal,\n\t);\n\n\t// A successful push changes what `pr://N` and `pr://N/diff` should show;\n\t// drop the cached rows so the canonical \"push → re-read diff\" flow sees\n\t// fresh data instead of a soft-TTL stale snapshot.","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/gh-pr-checkout.ts#L511-L547","documentation":"executePrPush resolves the branch to push: either the `branch` parameter or the current branch. It then verifies that branch actually exists locally via refExists; if not, there is nothing to push and it throws. Note this checks a real local branch — a detached HEAD or a typo'd name both land here.","triggerScenarios":"Running the pr_push op with `branch` set to a non-existent name; running on a detached HEAD where requireCurrentGitBranch / branch resolution yields a name with no local ref; branch was deleted locally but PR metadata still references it; typo in the branch parameter.","commonSituations":"Typo in --branch; after `git branch -D` cleanup the push op is retried; worktree/CI context where the branch was never created locally; detached HEAD during a rebase or bare-commit checkout.","solutions":["Check the exact name with `git branch --list <name>`; fix the typo in the branch parameter if it is misspelled.","Create or restore the branch: `git switch -c <branch>` (or `git switch <branch>` if it exists elsewhere), then re-run the push.","If HEAD is detached, create a branch at HEAD first (`git switch -c <branch>`) so a real local ref exists to push.","Verify you are in the right repository/worktree — the branch may exist in another worktree or clone."],"exampleFix":"// before\nop pr_push --branch fix-typo   // branch never created\n// after\ngit switch -c fix-typo\nop pr_push --branch fix-typo","handlingStrategy":"validation","validationCode":"const branch = params.branch ?? await repo.currentBranch();\nif (!branch || !(await repo.refExists(`refs/heads/${branch}`))) {\n  throw new Error(`local branch ${branch} does not exist — create it before pr_push`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await op.prPush({ branch });\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"does not exist\")) {\n    await git.switch([\"-c\", branch]); // create at HEAD, then retry\n    await op.prPush({ branch });\n  } else throw err;\n}","preventionTips":["Verify branch names with `git branch --list` before scripted pushes.","Don't run push ops on a detached HEAD — create a branch first.","Recreate deleted branches before retrying pushes.","Confirm you are in the intended worktree/clone."],"tags":["git","branch","pr-push","validation"],"backgroundTag":"branch-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}