diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index aea1b9ce2..0896efa30 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -167,7 +167,13 @@ export async function setupBranch( // Execute git commands to checkout PR branch (dynamic depth based on PR size) // Using execFileSync instead of shell template literals for security - execGit(["fetch", "origin", `--depth=${fetchDepth}`, branchName]); + // Use GitHub's PR ref which works for both same-repo and fork PRs + execGit([ + "fetch", + "origin", + `--depth=${fetchDepth}`, + `pull/${entityNumber}/head:${branchName}`, + ]); execGit(["checkout", branchName, "--"]); console.log(`Successfully checked out PR branch for PR #${entityNumber}`);