gitbutlerapp/gitbutler · error

Couldn't find branch to move in workspace with reference…

Error message

Couldn't find branch to move in workspace with reference name: {subject_branch_name}

What it means

tear_off_branch locates the branch to move by resolving its reference name against the workspace graph (find_segment_and_stack_by_refname). When the workspace contains no segment/stack for the given refname, the move cannot proceed and the function bails, echoing the requested name.

Solutions

  1. Verify the branch exists in the workspace (`but branch list` / git for-each-ref) and use the exact local refname
  2. Use the short branch name exactly as it appears in the workspace, not a fully qualified or remote name
  3. Refresh the workspace state after prior operations before retrying the move

Example fix

// before
tear_off_branch(..., "refs/remotes/origin/feature", ...);
// after
tear_off_branch(..., "feature", ...); // exact workspace-local refname
Defensive patterns

Strategy: validation

Validate before calling

fn branch_in_workspace(workspace: &Workspace, name: &str) -> bool {
    workspace.find_segment_and_stack_by_refname(name).is_some()
}

Try / catch

match result {
    Err(e) if e.to_string().contains("Couldn't find branch to move") => {
        eprintln!("refresh workspace state and confirm the exact local branch name");
        anyhow::bail!(e);
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling tear_off_branch with subject_branch_name that doesn't match any branch segment in the workspace graph (branch not in any stack, wrong name, or stale refname).

Common situations: Passing a remote-tracking name instead of the local workspace branch name; moving a branch that was already moved or deleted; name mismatch after a rebase rewrote branch structure.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-workspace/src/branch/move_branch.rs:67

    /// `workspace` - Used for getting the surrounding context of the branch being torn off.
    ///     In the future, we should not rely on the projection and do it fully on the graph.
    ///
    /// `subject_branch_name` - The branch to take out of a stack.
    ///
    /// `stack_id_override` - Optionally, the ID to use for the newly created stack.
    ///     Mainly used for testing purposes.
    ///
    /// Returns the in memory update [outcome](Outcome) that can then used for materialisation.
    pub fn tear_off_branch<'ws, 'meta, M: RefMetadata>(
        editor: Editor<'ws, 'meta, M>,
        subject_branch_name: &FullNameRef,
        stack_id_override: Option<StackId>,
    ) -> anyhow::Result<Outcome<'ws, 'meta, M>> {
        let successful_rebase = editor.rebase()?;
        let workspace = successful_rebase.overlayed_graph()?.into_workspace()?;
        let mut editor = successful_rebase.into_editor();
        let Some(source) = workspace.find_segment_and_stack_by_refname(subject_branch_name) else {
            bail!(
                "Couldn't find branch to move in workspace with reference name: {subject_branch_name}"
            );
        };

        // We're currently stopping the move branch operations imperatively at this stage, in order to
        // reduce the scope of this first iteration of moving the branches.
        // TODO: Enable and test that we can move branches in any kind of workspace.
        match &workspace.kind {
            WorkspaceKind::Managed { .. } => {}
            WorkspaceKind::ManagedMissingWorkspaceCommit { .. } => {
                bail!("Moving branches currently need a workspace commit")
            }
            WorkspaceKind::AdHoc => {
                bail!("Moving branches in non-managed workspaces is not supported");
            }
        };

        let mut ws_meta = workspace.metadata.clone();

View on GitHub (pinned to 58e5313667)