gitbutlerapp/gitbutler · error
Branch name ' ' collides with existing branch
Error message
Branch name '{}' collides with existing branch '{}' What it means
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.
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.
Example fix
// before
create_reference(repo, ref_name, ...)?; // fails if 'feature' vs 'feature/x' collide
// after
colliding = find_colliding_ref_ancestor(repo, ref_name);
if colliding.is_ok_and(|c| c.is_some()) {
return Err(anyhow!("pick a name not colliding with {}",
colliding.unwrap().unwrap().shorten()));
}
create_reference(repo, ref_name, ...)?; Defensive patterns
Strategy: validation
Validate before calling
fn branch_name_collides(repo: &gix::Repository, name: &gix::refs::PartialNameRef) -> bool {
but_workspace::branch::create_reference::find_colliding_ref_ancestor(repo, name)
.ok()
.flatten()
.is_some()
} Try / catch
match create_reference(repo, ref_name, ...) {
Err(e) if e.to_string().contains("collides with existing branch") => {
// extract the colliding branch from the message and ask the user for a new name
prompt_for_alternate_branch_name(&e.to_string())?;
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Can only check out local branches under refs/heads, got
- Can only check out local branches under refs/heads or…
- Can only delete local branches under refs/heads, got
- Can only rename local branches under refs/heads, got
- Cannot add the target
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/7a807956c855ba4b.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/create_reference.rs:509
belongs to another branch in the workspace. Each commit can only \
belong to one branch at a time.",
ref_name.shorten(),
ref_target_id,
)
}
// Actually apply the changes
repo.reference(
ref_name,
ref_target_id,
PreviousValue::ExistingMustMatch(gix::refs::Target::Object(ref_target_id)),
"Dependent branch by GitButler",
)
.map_err(|err| {
if is_not_a_directory_ref_edit_error(&err)
&& let Ok(Some(colliding_ref)) = find_colliding_ref_ancestor(repo, ref_name)
{
return anyhow::anyhow!(
"Branch name '{}' collides with existing branch '{}'",
ref_name.shorten(),
colliding_ref.shorten()
);
}
let code = match err {
gix::reference::edit::Error::FileTransactionCommit(
gix::refs::file::transaction::commit::Error::CreateOrUpdateRefLog(
gix::refs::file::log::create_or_update::Error::MissingCommitter,
),
) => Some(but_error::Code::AuthorMissing),
_ => None,
};
let err = anyhow::Error::from(err);
if let Some(code) = code {
err.context(code)
} else {
errView on GitHub (pinned to 58e5313667)