gitbutlerapp/gitbutler · error
Invalid branch name
Error message
Invalid branch name: {err} What it means
Raised by `normalize_local_branch_ref` (crates/but/src/command/branch/update.rs:164) when the normalized branch name fails `FullName::try_from`. Only local branches under `refs/heads/` are supported; any other syntax produces an invalid full reference name and the underlying git validation error is interpolated into the message.
Solutions
- Check the branch name against `git check-ref-format --branch <name>` and fix invalid characters
- Use the short branch name (e.g. `feature/foo`) rather than a full ref path
- For remote branches, create a matching local branch first — only `refs/heads/` refs are supported
- Quote the branch name in the shell to avoid stray characters being injected
Example fix
// before but branch update "feature..foo" // invalid ref name // after but branch update "feature-foo"
Defensive patterns
Strategy: validation
Validate before calling
// validate like git does before invoking the command
let out = std::process::Command::new("git")
.args(["check-ref-format", "--branch", branch])
.status()?;
if !out.success() { return Err(format!("invalid branch name: {branch}")); } Type guard
fn is_valid_local_branch_name(name: &str) -> bool {
!name.starts_with("refs/") && gix::refs::FullName::try_from(format!("refs/heads/{name}")).is_ok()
} Try / catch
match cmd_branch_update(branch) {
Err(e) if e.to_string().contains("Invalid branch name") => eprintln!("use a valid branch name: git check-ref-format --branch"),
other => other?,
} Prevention
- Validate branch names with git check-ref-format before use
- Pass short names, never refs/remotes/... paths
- Quote branch names in shell scripts
When it happens
Trigger: Calling the branch update command with a name that normalizes to an invalid ref — containing spaces, `..`, `~`, `^`, `:`, control characters, or starting with `refs/` but pointing outside `refs/heads/` (which is rejected earlier).
Common situations: Typing a branch name with illegal characters in the CLI; passing `refs/remotes/origin/foo` or other non-heads refs; shell quoting issues injecting stray characters; overly long branch names.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Aborting due to empty branch name
- Bare repositories are not supported.
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Branch " " has no conflicted commits.
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/69b8a7be52ee9158.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/branch/update.rs:164
reference.name.shorten()
)
}
_ => bail!(
"Expected a local branch, but '{}' is not under refs/heads/",
reference.name.shorten()
),
}
}
fn normalize_local_branch_ref(branch: &str) -> anyhow::Result<FullName> {
let full = if branch.starts_with("refs/heads/") {
branch.to_owned()
} else if branch.starts_with("refs/") {
bail!("Only local branches under refs/heads/ are supported");
} else {
format!("refs/heads/{branch}")
};
FullName::try_from(full).map_err(|err| anyhow::anyhow!("Invalid branch name: {err}"))
}
fn output_apply_result(
branch_ref: &FullNameRef,
divergence: &but_workspace::branch::IntegrationDivergenceDisplay,
dry_run: bool,
verbose: bool,
result: IntegrateBranchResult,
out: &mut OutputChannel,
) -> anyhow::Result<()> {
if let Some(out) = out.for_human() {
if dry_run {
write!(
out,
"{}",
format_dry_run(divergence, branch_ref, &result, verbose)
)?;
} else {View on GitHub (pinned to 58e5313667)