Skip to content

Worktree is branched off local main instead of origin/main #59

@Seretos

Description

@Seretos

#ai-generated

Bug Report

When creating a worktree, the library branches off the local main branch rather than fetching the latest state from origin first. If the local main is behind origin/main (e.g. because the user has not manually pulled), the new worktree starts from an outdated commit.

Root Cause

In manager.py the worktree is created with:

git worktree add -b fix/<nr>-<slug> <path> main

The base main resolves to the local ref refs/heads/main. There is no git fetch origin call anywhere in the creation path — neither in manager.py, worktrees.py, nor in the callers (workboard backend / lib consumers).

Steps to Reproduce

  1. Clone a repository where origin/main is ahead of local main (or simply don't pull for a while).
  2. Create a worktree via the workboard or directly via the lib.
  3. Check the base commit of the new branch: it is behind origin/main.

Expected Behavior

The new worktree/branch should always start from the latest origin/main so agents work on an up-to-date codebase. Concretely:

git fetch origin main
git worktree add -b fix/<nr>-<slug> <path> origin/main

Using origin/main as the base directly avoids having to update the local main branch, which could have uncommitted state or be checked out elsewhere.

Proposed Fix

In manager.py, before the git worktree add call, run:

subprocess.run(["git", "fetch", "origin", base_branch], cwd=repo_path, check=True)

Then change the base ref passed to git worktree add from main (local) to origin/main (remote tracking ref). The fetch can be skipped with a flag (e.g. fetch: bool = True) to support offline/air-gapped scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-generatedCreated by the project-issues AI agentbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions