{"record":{"id":"7a807956c855ba4b","repo":"gitbutlerapp/gitbutler","slug":"branch-name-collides-with-existing-branch","errorCode":null,"errorMessage":"Branch name '{}' collides with existing branch '{}'","messagePattern":"Branch name '(.+?)' collides with existing branch '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/create_reference.rs","lineNumber":509,"sourceCode":"                 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)\n            {\n                return anyhow::anyhow!(\n                    \"Branch name '{}' collides with existing branch '{}'\",\n                    ref_name.shorten(),\n                    colliding_ref.shorten()\n                );\n            }\n            let code = match err {\n                gix::reference::edit::Error::FileTransactionCommit(\n                    gix::refs::file::transaction::commit::Error::CreateOrUpdateRefLog(\n                        gix::refs::file::log::create_or_update::Error::MissingCommitter,\n                    ),\n                ) => Some(but_error::Code::AuthorMissing),\n                _ => None,\n            };\n            let err = anyhow::Error::from(err);\n            if let Some(code) = code {\n                err.context(code)\n            } else {\n                err","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/create_reference.rs#L491-L527","documentation":"Thrown when creating a branch reference fails because the requested ref name collides with an existing branch whose ref path is an ancestor (e.g. creating branch 'foo' when 'foo/bar' exists, or vice versa — Git refs are stored as files/directories so 'foo' and 'foo/bar' cannot coexist). The helper find_colliding_ref_ancestor locates the conflicting existing ref and the error names both branches.","triggerScenarios":"Calling create_reference (branch creation) with a ref_name for which find_colliding_ref_ancestor finds an existing ref occupying a conflicting path in the refs namespace, and the underlying git error is a 'not a directory' style ref-edit error.","commonSituations":"Creating branch 'feature' when 'feature/x' already exists; creating 'feature/x' when 'feature' exists; slashes in user-provided branch names clashing with existing hierarchies; leftover refs from prior automation.","solutions":["Choose a different branch name that does not conflict with any existing branch or branch prefix (the error names the colliding branch).","List existing branches (but branch list / git branch) and check whether any branch name is a path prefix of the requested name, or vice versa.","Delete or rename the colliding branch if it is no longer needed, then retry.","Programmatically pre-check with find_colliding_ref_ancestor (or gix refname collision rules) before calling create_reference."],"exampleFix":"// before\ncreate_reference(repo, ref_name, ...)?; // fails if 'feature' vs 'feature/x' collide\n// after\ncolliding = find_colliding_ref_ancestor(repo, ref_name);\nif colliding.is_ok_and(|c| c.is_some()) {\n    return Err(anyhow!(\"pick a name not colliding with {}\",\n        colliding.unwrap().unwrap().shorten()));\n}\ncreate_reference(repo, ref_name, ...)?;","handlingStrategy":"validation","validationCode":"fn branch_name_collides(repo: &gix::Repository, name: &gix::refs::PartialNameRef) -> bool {\n    but_workspace::branch::create_reference::find_colliding_ref_ancestor(repo, name)\n        .ok()\n        .flatten()\n        .is_some()\n}","typeGuard":null,"tryCatchPattern":"match create_reference(repo, ref_name, ...) {\n    Err(e) if e.to_string().contains(\"collides with existing branch\") => {\n        // extract the colliding branch from the message and ask the user for a new name\n        prompt_for_alternate_branch_name(&e.to_string())?;\n    }\n    other => other?,\n}","preventionTips":["Check existing branch names for prefix/child relationships before creating a branch.","Discourage branch names that are path prefixes of existing branches (and vice versa).","Sanitize user-provided branch names to a consistent scheme (e.g. forbid bare prefixes like 'feature' when 'feature/*' exists).","Clean up stale hierarchical branches left by automation."],"tags":["git","branch","refname-collision","validation"],"backgroundTag":"file-already-exists","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"}