gitbutlerapp/gitbutler · warning

Cannot move branch onto itself

Error message

Cannot move branch {subject_branch_name} onto itself

What it means

move_branch() refuses to move a branch onto itself: subject_branch_name and target_branch_name are equal, which is a no-op with ambiguous semantics (source and destination would be the same segment). The check happens before any rebase or graph work.

Solutions

  1. Compare subject and target branch names before calling move_branch and skip identical pairs
  2. Use fully-qualified ref names for the comparison to avoid false equality/inequality
  3. Return a no-op success instead of an error when names match, in the caller

Example fix

// before
move_branch(editor, name, target)
// after
if name != target {
    move_branch(editor, name, target)
}
Defensive patterns

Strategy: validation

Validate before calling

if subject_branch_name == target_branch_name {
    return Ok(()); // no-op
}

Try / catch

match move_branch(editor, subject, target) {
    Err(e) if e.to_string().contains("onto itself") => return Ok(()),
    other => other?,
}

Prevention

When it happens

Trigger: Calling move_branch(editor, "gitbutler/workspace/foo", "gitbutler/workspace/foo") - the same fully-qualified ref passed as both subject and target.

Common situations: UI/CLI bugs where the user drags a branch onto itself; building target branch name from user input without dedup check; automated scripts iterating over stacks and accidentally pairing a ref with itself.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

    /// `editor` is assumed to have been generated from the given `workspace`
    /// and therefore aligned.
    ///
    /// `workspace` - Used for getting the surrounding context of the branch being moved.
    ///     In the future, we should not rely on the projection and do it fully on the graph.
    ///
    /// `subject_branch_name` is the full reference name of the branch to move.
    ///
    /// `target_branch_name` is the full reference name of the branch to move the subject
    /// branch on top of.
    ///
    /// Returns an [outcome](Outcome) for potential materialisation.
    pub fn move_branch<'ws, 'meta, M: RefMetadata>(
        editor: Editor<'ws, 'meta, M>,
        subject_branch_name: &FullNameRef,
        target_branch_name: &FullNameRef,
    ) -> anyhow::Result<Outcome<'ws, 'meta, M>> {
        if subject_branch_name == target_branch_name {
            bail!("Cannot move branch {subject_branch_name} onto itself");
        }

        let successful_rebase = editor.rebase()?;
        let workspace = successful_rebase.overlayed_graph()?.into_workspace()?;

        let (source, destination) =
            retrieve_branches_and_containers(&workspace, subject_branch_name, target_branch_name)?;

        // Each kind of workspace has a very different notion of what "moving a branch" means, so we
        // dispatch into a dedicated handler for each one.
        match &workspace.kind {
            WorkspaceKind::AdHoc => move_branch_in_single_branch_mode(
                successful_rebase,
                workspace,
                source,
                destination,
                subject_branch_name,
                target_branch_name,

View on GitHub (pinned to 58e5313667)