gitbutlerapp/gitbutler · error

Branch ` ` is not part of the current workspace

Error message

Branch `{}` is not part of the current workspace

What it means

lane_chain_for_branch resolves a branch to its lane chain within the workspace RefInfo. If info.lane_chain() returns an empty chain, the branch is not part of the current workspace, and this error is thrown with the branch name.

Solutions

  1. Apply the branch to the workspace (e.g. `but branch apply` / workspace UI) before creating a review
  2. Verify the branch name/ref is correct and currently applied
  3. Create the review from a branch that is part of the workspace
Defensive patterns

Strategy: validation

Validate before calling

const applied = await getWorkspaceBranches(projectId);
if (!applied.some(b => b.ref === branchRef)) {
  await applyBranchToWorkspace(projectId, branchRef);
}

Try / catch

try {
  await createReview(projectId, branchRef);
} catch (e) {
  if (String(e).includes('not part of the current workspace')) {
    await applyBranchToWorkspace(projectId, branchRef);
    await createReview(projectId, branchRef);
  } else throw e;
}

Prevention

When it happens

Trigger: Creating a review for a branch that exists in the repo but is not included in any workspace lane (not applied/managed by the workspace).

Common situations: Selecting a stale or archived branch for review; branch was unapplied from the workspace; typos or refs from outside the workspace being passed to review creation.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/d4186b223c41f52b. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-api/src/legacy/forge.rs:2251

    match reviewed_ancestors.pop() {
        Some(nearest_reviewed_ancestor) => Ok(nearest_reviewed_ancestor.branch_name),
        None => target_short_name(&ctx.project_meta()?, &repo),
    }
}

#[derive(Debug)]
struct RemoteHead {
    branch_name: String,
    remote_tip: gix::ObjectId,
}

fn lane_chain_for_branch<'a>(
    info: &'a but_workspace::RefInfo,
    branch: &gix::refs::FullNameRef,
) -> Result<Vec<(but_workspace::ref_info::Lane<'a>, usize)>> {
    let chain = info.lane_chain(branch);
    if chain.is_empty() {
        anyhow::bail!(
            "Branch `{}` is not part of the current workspace",
            branch.shorten()
        );
    }
    Ok(chain)
}

/// The numbers of reviews the forge cache currently knows as open.
///
/// The mutation flows gate on this: only an open review is a valid target for
/// retargeting, footer syncs, creation targets, or merge selection. A
/// segment's metadata number can also be settled display state — an
/// integrated branch's landed identity, or a merge still awaiting
/// integration detection — which must never reach the forge as a mutation.
pub fn open_review_numbers(ctx: &Context) -> Result<std::collections::HashSet<i64>> {
    let db = ctx.db.get_cache()?;
    Ok(but_forge::cached_review_states(&db)?
        .into_iter()

View on GitHub (pinned to 58e5313667)