gitbutlerapp/gitbutler · error

Aborting due to empty branch name

Error message

Aborting due to empty branch name

What it means

The `but` CLI opens the user's editor to collect a new branch name during branch-reword/creation flows (`get_branch_name_from_editor`). After the editor closes, the trimmed text is checked and if nothing remains the command aborts with this error instead of creating an empty-named branch, which Git refs cannot represent.

Solutions

  1. Re-run the command and type a valid branch name before saving and closing the editor
  2. Ensure GIT_EDITOR/EDITOR/core.editor points to an editor that actually saves content (not `true`, `cat > /dev/null`, etc.)
  3. When scripting, pre-seed or pipe the desired branch name instead of relying on the interactive editor
  4. Check the saved file has no leading/trailing whitespace-only content; comments starting with `#` are stripped

Example fix

// before (scripted, always aborts)
GIT_EDITOR=true but branch create

// after (provide a real name via editor content or a non-interactive path)
export GIT_EDITOR="sh -c 'echo my-branch > "$1"' --"
but branch create
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
# ensure the editor produces non-empty, non-comment content
name=$(git var GIT_EDITOR >/dev/null 2>&1 && echo ok)
[ -n "$name" ] || { echo "no editor configured"; exit 1; }

Try / catch

match but_branch_create_result {
    Err(e) if e.to_string().contains("Aborting due to empty branch name") => {
        eprintln!("editor produced an empty branch name; retry with a name");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling `but branch create`, `but branch reword`/edit-name flows where the user (or a scripted `GIT_EDITOR`) closes the editor with an empty file, deletes all typed content, or leaves only comment lines that `from_editor_no_comments` strips out.

Common situations: Running the command non-interactively with an editor like `true` or `:` as GIT_EDITOR; automating the CLI in CI with a misconfigured editor; a user accidentally clearing the editor buffer; templates whose only content is `#` comment lines.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/but/src/command/legacy/reword2.rs:235

    Ok(operation)
}

pub(crate) fn get_branch_name_from_editor(current_name: &str) -> anyhow::Result<String> {
    let mut template = String::new();
    template.push_str(current_name);
    if !current_name.is_empty() && !current_name.ends_with('\n') {
        template.push('\n');
    }
    template.push_str("\n# Please enter the new branch name. Lines starting\n");
    template.push_str("# with '#' will be ignored, and an empty name aborts the operation.\n");
    template.push_str("#\n");

    let branch_name =
        crate::tui::get_text::from_editor_no_comments("branch_name", &template)?.to_string();
    let branch_name = branch_name.trim();
    if branch_name.is_empty() {
        anyhow::bail!("Aborting due to empty branch name");
    }
    Ok(branch_name.to_owned())
}

pub fn run(
    ctx: &mut Context,
    meta: &mut impl RefMetadata,
    perm: &mut RepoExclusive,
    operation: RewordOperation,
) -> CliResult<(RewordOutcome, Option<WorkspaceState>)> {
    match operation {
        RewordOperation::Commit {
            target,
            new_message: message,
        } => {
            let commit_details = {
                let repo = ctx.repo.get()?;
                CommitDetails::from_commit_id(

View on GitHub (pinned to 58e5313667)