{"record":{"id":"abc17d544133900c","repo":"gitbutlerapp/gitbutler","slug":"branch-cannot-be-created-the-target-commit","errorCode":null,"errorMessage":"Branch '{}' cannot be created: the target commit ({}) already belongs to another branch in the workspace. Each commit can only belong to one branch at a time.","messagePattern":"Branch '(.+?)' cannot be created: the target commit \\((.+?)\\) already belongs to another branch in the workspace\\. Each commit can only belong to one branch at a time\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/create_reference.rs","lineNumber":489,"sourceCode":"        };\n\n        let updated_workspace = graph_with_new_ref.into_workspace()?;\n        let has_new_ref_as_standalone_segment = updated_workspace\n            .find_segment_and_stack_by_refname(ref_name)\n            .is_some();\n        let existing_ref_is_in_workspace = existing_ref_target_in_workspace.is_some();\n        if !has_new_ref_as_standalone_segment {\n            if existing_ref_target_id.is_some()\n                && !existing_ref_is_in_workspace\n                && !workspace.refname_is_segment(ref_name)\n                && workspace.ref_name() != Some(ref_name)\n            {\n                bail_precondition!(\n                    \"Reference '{}' already exists and is outside the workspace\",\n                    ref_name.shorten()\n                );\n            }\n            bail!(\n                \"Branch '{}' cannot be created: the target commit ({}) already \\\n                 belongs to another branch in the workspace. Each commit can only \\\n                 belong to one branch at a time.\",\n                ref_name.shorten(),\n                ref_target_id,\n            )\n        }\n\n        // Actually apply the changes\n        repo.reference(\n            ref_name,\n            ref_target_id,\n            PreviousValue::ExistingMustMatch(gix::refs::Target::Object(ref_target_id)),\n            \"Dependent branch by GitButler\",\n        )\n        .map_err(|err| {\n            if is_not_a_directory_ref_edit_error(&err)\n                && let Ok(Some(colliding_ref)) = find_colliding_ref_ancestor(repo, ref_name)","sourceCodeStart":471,"sourceCodeEnd":507,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/create_reference.rs#L471-L507","documentation":"GitButler enforces that each commit belongs to exactly one branch within a workspace. When creating a reference whose target commit is already claimed by another branch in the same workspace, creation is refused because two branches cannot share ownership of a commit.","triggerScenarios":"Calling `create_reference` with a target commit id that is the head (or part) of another branch's segment in the workspace — e.g. reusing an existing commit hash as the new branch's target.","commonSituations":"Creating a branch from a commit id copied from another branch's log; automation that picks a commit without checking ownership; trying to duplicate a branch target within one workspace.","solutions":["Create the branch at a commit not owned by any workspace branch (e.g. a new commit on top)","Remove or move the existing branch that owns the commit before creating the new one","Use branch creation from the workspace UI, which picks an unowned commit automatically"],"exampleFix":"// before\ncreate_reference(meta, repo, \"feature\", other_branch_commit_id)?;\n// after\nlet free_commit = repo.commit_create_or_fail(parent, tree, msg)?; // commit not in any segment\ncreate_reference(meta, repo, \"feature\", free_commit)?;","handlingStrategy":"validation","validationCode":"let owned = workspace.all_segments()\n    .flat_map(|s| s.commits())\n    .any(|c| c.id == target_commit);\nif owned {\n    return Err(\"target commit already belongs to a workspace branch\");\n}","typeGuard":null,"tryCatchPattern":"match create_reference(...) {\n    Err(e) if e.to_string().contains(\"already belongs to another branch\") => /* pick a different commit or remove the owning branch */,\n    Err(e) => return Err(e.into()),\n    Ok(r) => r,\n}","preventionTips":["Create branches from fresh commits rather than existing branch heads","Check workspace segment ownership before targeting a commit","Deduplicate branch targets when automating branch creation"],"tags":["git","workspace","conflict"],"backgroundTag":"invalid-state-transition","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"}