{"record":{"id":"471ef708a694bd06","repo":"gitbutlerapp/gitbutler","slug":"couldn-t-find-branch-to-move-in-workspace-with-ref","errorCode":null,"errorMessage":"Couldn't find branch to move in workspace with reference name: {subject_branch_name}","messagePattern":"Couldn't find branch to move in workspace with reference name: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/move_branch.rs","lineNumber":67,"sourceCode":"    /// `workspace` - Used for getting the surrounding context of the branch being torn off.\n    ///     In the future, we should not rely on the projection and do it fully on the graph.\n    ///\n    /// `subject_branch_name` - The branch to take out of a stack.\n    ///\n    /// `stack_id_override` - Optionally, the ID to use for the newly created stack.\n    ///     Mainly used for testing purposes.\n    ///\n    /// Returns the in memory update [outcome](Outcome) that can then used for materialisation.\n    pub fn tear_off_branch<'ws, 'meta, M: RefMetadata>(\n        editor: Editor<'ws, 'meta, M>,\n        subject_branch_name: &FullNameRef,\n        stack_id_override: Option<StackId>,\n    ) -> anyhow::Result<Outcome<'ws, 'meta, M>> {\n        let successful_rebase = editor.rebase()?;\n        let workspace = successful_rebase.overlayed_graph()?.into_workspace()?;\n        let mut editor = successful_rebase.into_editor();\n        let Some(source) = workspace.find_segment_and_stack_by_refname(subject_branch_name) else {\n            bail!(\n                \"Couldn't find branch to move in workspace with reference name: {subject_branch_name}\"\n            );\n        };\n\n        // We're currently stopping the move branch operations imperatively at this stage, in order to\n        // reduce the scope of this first iteration of moving the branches.\n        // TODO: Enable and test that we can move branches in any kind of workspace.\n        match &workspace.kind {\n            WorkspaceKind::Managed { .. } => {}\n            WorkspaceKind::ManagedMissingWorkspaceCommit { .. } => {\n                bail!(\"Moving branches currently need a workspace commit\")\n            }\n            WorkspaceKind::AdHoc => {\n                bail!(\"Moving branches in non-managed workspaces is not supported\");\n            }\n        };\n\n        let mut ws_meta = workspace.metadata.clone();","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/move_branch.rs#L49-L85","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the branch exists in the workspace (`but branch list` / git for-each-ref) and use the exact local refname","Use the short branch name exactly as it appears in the workspace, not a fully qualified or remote name","Refresh the workspace state after prior operations before retrying the move"],"exampleFix":"// before\ntear_off_branch(..., \"refs/remotes/origin/feature\", ...);\n// after\ntear_off_branch(..., \"feature\", ...); // exact workspace-local refname","handlingStrategy":"validation","validationCode":"fn branch_in_workspace(workspace: &Workspace, name: &str) -> bool {\n    workspace.find_segment_and_stack_by_refname(name).is_some()\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Couldn't find branch to move\") => {\n        eprintln!(\"refresh workspace state and confirm the exact local branch name\");\n        anyhow::bail!(e);\n    }\n    other => other,\n}","preventionTips":["Use the exact workspace-local (short) branch name, not remote or fully qualified names","Refresh workspace state after other operations before moving branches","Confirm the branch belongs to a stack before attempting a move"],"tags":["git","workspace","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}