gitbutlerapp/gitbutler · error
Moving branches currently need a workspace commit
Error message
Moving branches currently need a workspace commit
What it means
Branch moving currently requires a workspace with an actual workspace commit. A ManagedMissingWorkspaceCommit workspace (managed but missing its workspace commit) is rejected because the rebase/overlay machinery underpinning the move has no commit to build on. The code marks this limitation with a TODO.
Solutions
- Restore or recreate the workspace commit (commit pending workspace changes) before moving branches
- Recreate the workspace/stack via the library's normal creation flow so a workspace commit exists
- Move the branch with plain git operations if the workspace is broken
- awaiting library support for commit-less workspaces
Example fix
// before move_branch.tear_off_branch(...)?; // workspace missing its commit // after workspace.commit_missing_workspace_commit()?; // ensure a workspace commit exists teardown = move_branch.tear_off_branch(...);
Defensive patterns
Strategy: validation
Validate before calling
fn movable_workspace(workspace: &Workspace) -> bool {
matches!(workspace.kind, WorkspaceKind::Managed { .. })
} Try / catch
match result {
Err(e) if e.to_string().contains("need a workspace commit") => {
eprintln!("recreate the workspace commit before moving branches");
anyhow::bail!(e);
}
other => other,
} Prevention
- Avoid resetting/rewriting the workspace branch with raw git commands
- Commit or restore workspace state before branch operations
- Check WorkspaceKind before invoking move operations
When it happens
Trigger: Calling tear_off_branch against a workspace whose WorkspaceKind is ManagedMissingWorkspaceCommit — e.g. after the workspace commit was deleted, reset away, or a stack was emptied.
Common situations: Workspaces whose last commit was removed by external git commands (`git reset --hard` on the workspace branch, history rewriting tools), or freshly initialized managed workspaces that haven't committed yet.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' cannot be created: the target commit ( ) already…
- BranchNotFound
- BUG: failed to apply head ref
- Cannot add the target
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/176883324a12c632.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/move_branch.rs:78
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();
let (source_stack, subject_segment) = source;
if source_stack.segments.len() == 1 {
// There's only one branch in the source stack. Nothing to do.
return Ok(Outcome {
rebase: editor.rebase()?,
ws_meta,
new_tip: None,
branch_stack_order: None,
});View on GitHub (pinned to 58e5313667)