gitbutlerapp/gitbutler · error
Couldn't find target branch to move in workspace with…
Error message
Couldn't find target branch to move in workspace with reference name: {target_branch_name} What it means
The counterpart to the subject lookup: move_branch() resolves the target branch's segment/stack in the workspace graph. When find_segment_and_stack_by_refname finds no segment for target_branch_name, the destination is unknown and the function bails.
Solutions
- Verify the target branch exists within the workspace and use its fully-qualified ref name
- Re-read the workspace graph/stack listing to get valid target ref names
- Handle the case where the intended destination is outside the workspace - use a different operation
Example fix
// before move_branch(editor, subject, "target") // after let target = "refs/heads/target"; // must exist in the workspace graph move_branch(editor, subject, target)
Defensive patterns
Strategy: validation
Validate before calling
let target_ok = workspace.find_segment_and_stack_by_refname(target_branch_name).is_some();
if !target_ok { /* target not in workspace: abort or choose another target */ } Try / catch
match move_branch(editor, subject, target) {
Err(e) if e.to_string().contains("Couldn't find target branch") => refresh_and_pick_target_from_graph(),
other => other?,
} Prevention
- Derive move targets from the live workspace graph, not cached UI state
- Use fully-qualified refs for targets
- Re-validate targets after any concurrent workspace change
When it happens
Trigger: Calling move_branch() with a target_branch_name that has no segment in the workspace graph - the target ref does not exist in the workspace, was deleted, or was passed unqualified.
Common situations: Passing a base/upstream ref or a branch outside the workspace as the move target; target branch renamed or deleted concurrently; UI passing a stale ref name after a refresh.
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
- Couldn't find branch to move in workspace with reference…
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Branch ' ' cannot be created: the target commit ( ) already…
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/a393eb7f0c1a285f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/move_branch.rs:505
///
/// ### What the future holds
/// In the future, where we're not afraid of complex graphs, we've figured out UX and data wrangling,
/// the concept of a segment might not hold, and hence we'll have to figure out a better way of determining
/// what to cut (e.g. letting the clients decide what to cut).
fn retrieve_branches_and_containers(
workspace: &but_graph::Workspace,
subject_branch_name: &FullNameRef,
target_branch_name: &FullNameRef,
) -> anyhow::Result<(WorkspaceSegmentContext, WorkspaceSegmentContext)> {
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}"
);
};
let Some(destination) = workspace.find_segment_and_stack_by_refname(target_branch_name)
else {
bail!(
"Couldn't find target branch to move in workspace with reference name: {target_branch_name}"
);
};
Ok((own_context(source), own_context(destination)))
}
/// Reorder `subject` to sit directly on top of `target` in the tip-to-base ad-hoc `order`.
///
/// Mirrors the [`Position::Above`](crate::branch::create_reference::Position) case of
/// `create_reference`'s `insert_into_branch_stack_order`: `subject` is removed and re-inserted
/// at `target`'s slot, pushing `target` (and everything below it) down.
///
/// If `target` isn't tracked yet (stale or empty metadata) it is appended first, so that a move
/// where *both* branches are missing adds them both - `subject` on top of `target` - instead of
/// silently clobbering the rest of the ordering down to just `subject`.
fn reorder_branch_in_stack_order(
mut order: Vec<gix::refs::FullName>,
target_branch_name: &FullNameRef,View on GitHub (pinned to 58e5313667)