From 93df09fd88688c19bd9e4ca40e5c7281cba39ed1 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Sat, 19 Jul 2025 08:26:59 -0700 Subject: [PATCH] fix: checkout base branch before creating new branches (#311) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix bug where base_branch parameter was not being respected - Add git fetch and checkout of source branch before creating new branch - Ensures new branches are created from specified base_branch instead of current HEAD - Fixes issue #268 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude --- src/github/operations/branch.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index 68e8b0e..0d31da8 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -116,6 +116,11 @@ export async function setupBranch( `Branch name generated: ${newBranch} (will be created by file ops server on first commit)`, ); + // Ensure we're on the source branch + console.log(`Fetching and checking out source branch: ${sourceBranch}`); + await $`git fetch origin ${sourceBranch} --depth=1`; + await $`git checkout ${sourceBranch}`; + // Set outputs for GitHub Actions core.setOutput("CLAUDE_BRANCH", newBranch); core.setOutput("BASE_BRANCH", sourceBranch); @@ -131,7 +136,12 @@ export async function setupBranch( `Creating local branch ${newBranch} for ${entityType} #${entityNumber} from source branch: ${sourceBranch}...`, ); - // Create and checkout the new branch locally + // Fetch and checkout the source branch first to ensure we branch from the correct base + console.log(`Fetching and checking out source branch: ${sourceBranch}`); + await $`git fetch origin ${sourceBranch} --depth=1`; + await $`git checkout ${sourceBranch}`; + + // Create and checkout the new branch from the source branch await $`git checkout -b ${newBranch}`; console.log(