{"record":{"id":"a6d68b89cc4057f4","repo":"gitbutlerapp/gitbutler","slug":"could-not-create-branch","errorCode":null,"errorMessage":"Could not create branch '{}'","messagePattern":"Could not create branch '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/branch.rs","lineNumber":1411,"sourceCode":"            if let Err(delete_err) = old_reference.delete() {\n                if let Some(backup) = backup_reference.take()\n                    && let Err(err) = backup.delete()\n                {\n                    warn!(\n                        ?err,\n                        \"failed to remove branch-rename recovery ref after source deletion failed\"\n                    );\n                }\n                return Err(anyhow::Error::new(delete_err)\n                    .context(format!(\"Could not delete branch '{}'\", ref_name.as_bstr())));\n            }\n            if let Err(create_err) = repo.reference(\n                new_ref.as_ref(),\n                target_id,\n                PreviousValue::MustNotExist,\n                \"rename branch\",\n            ) {\n                let create_err = anyhow::Error::new(create_err)\n                    .context(format!(\"Could not create branch '{}'\", new_ref.as_bstr()));\n                match repo.reference(\n                    ref_name.as_ref(),\n                    target_id,\n                    PreviousValue::MustNotExist,\n                    \"restore branch after failed rename\",\n                ) {\n                    Ok(_) => {\n                        if let Some(backup) = backup_reference.take()\n                            && let Err(err) = backup.delete()\n                        {\n                            warn!(\n                                ?err,\n                                \"failed to remove branch-rename recovery ref after restoring source\"\n                            );\n                        }\n                        return Err(create_err);\n                    }","sourceCodeStart":1393,"sourceCodeEnd":1429,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/branch.rs#L1393-L1429","documentation":"Raised during branch rename when creating the new reference with repo.reference(..., PreviousValue::MustNotExist) fails. The error is wrapped with context 'Could not create branch <name>' and the code then attempts to restore the old ref; if restoration also fails the create_err is returned to the caller.","triggerScenarios":"Renaming a branch to a name that already exists as a reference (MustNotExist violated), an invalid ref name, or an I/O error writing the new ref file.","commonSituations":"User picks a target name that already exists in the repo, uses invalid characters or casing that collides on case-insensitive filesystems (Windows/macOS), or a stale ref left from a previously failed rename.","solutions":["Choose a target branch name that does not already exist","Remove the stale leftover reference from an earlier failed rename (git branch -D or git update-ref -d)","Use a valid ref name (no spaces, no trailing '.lock', no '..')","Check case-collisions on case-insensitive filesystems"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (await api.branchExists(newName)) throw new Error(`branch '${newName}' already exists`);","typeGuard":null,"tryCatchPattern":"try { api.renameBranch(old, new); } catch (e) { if (String(e).includes('Could not create branch')) { console.error('target name taken or invalid:', new); } throw e; }","preventionTips":["Check the target name against existing branches before renaming","Validate ref-name syntax (no spaces, '..', or '.lock' suffix)","Clean up stale refs after failed renames before retrying"],"tags":["git","branch-rename","ref-creation","name-conflict"],"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"}