{"record":{"id":"4603868594a8547e","repo":"pcottle/learnGitBranching","slug":"git-error-branch","errorCode":null,"errorMessage":"git-error-branch","messagePattern":"git-error-branch","errorType":"validation","errorClass":"GitError","httpStatus":null,"severity":"error","filePath":"src/js/git/index.js","lineNumber":2732,"sourceCode":"};\n\nGitEngine.prototype.branch = function(name, ref) {\n  var target = this.getCommitFromRef(ref);\n  var newBranch = this.validateAndMakeBranch(name, target);\n\n  ref = this.resolveID(ref);\n  if (this.isRemoteBranchRef(ref)) {\n    this.setLocalToTrackRemote(newBranch, ref);\n  }\n};\n\nGitEngine.prototype.renameBranch = function(oldName, newName) {\n  oldName = this.crappyUnescape(oldName);\n  newName = this.validateBranchName(newName);\n\n  var branch = this.resolveID(oldName);\n  if (branch.get('type') !== 'branch' || branch.getIsRemote()) {\n    throw new GitError({\n      msg: intl.str('git-error-branch')\n    });\n  }\n\n  if (this.doesRefExist(newName)) {\n    throw new GitError({\n      msg: intl.str(\n        'bad-branch-name',\n        { branch: newName }\n      )\n    });\n  }\n\n  delete this.refs[oldName];\n  branch.set('id', newName);\n  this.refs[newName] = branch;\n};\n","sourceCodeStart":2714,"sourceCodeEnd":2750,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/index.js#L2714-L2750","documentation":"Thrown by the first (legacy) renameBranch implementation when the resolved ref for the old branch name is not a local branch (e.g. it resolved to a commit, tag, or HEAD) or when it is a remote tracking branch (o/*). Git refuses to rename anything that is not a local branch, and the simulator mirrors that behavior by throwing a GitError with the localized 'git-error-branch' message.","triggerScenarios":"Calling the engine's renameBranch('foo','bar') where 'foo' resolves via resolveID to a non-branch ref (a tag, a commit id, HEAD) or to a remote branch (getIsRemote() true). Typically reached from a 'git branch -m foo bar' command when foo does not exist as a local branch.","commonSituations":"Typos in the old branch name; renaming a remote tracking branch like o/main; trying to rename a tag; using a commit hash as the first argument.","solutions":["Verify the old name is an existing local branch (git branch output) before renaming","If you meant a remote branch, create a new local branch instead of renaming the remote ref","Check for typos/hashes/tags passed as the old branch name"],"exampleFix":"// before\nengine.renameBranch('o/main', 'main2');\n// after\nengine.renameBranch('main', 'main2');","handlingStrategy":"validation","validationCode":"var ref = engine.resolveID(oldName);\nif (!ref || ref.get('type') !== 'branch' || ref.getIsRemote()) {\n  // pick another name or bail\n}","typeGuard":"function isLocalBranch(engine, name) {\n  var r = engine.resolveID(name);\n  return !!r && r.get('type') === 'branch' && !r.getIsRemote();\n}","tryCatchPattern":"try { engine.renameBranch(a, b); } catch (e) { if (e instanceof GitError && e.msg === intl.str('git-error-branch')) { /* handle */ } else throw e; }","preventionTips":["Validate ref type before rename","Never pass o/* refs or tags to renameBranch"],"tags":["git","branch","rename","ref-validation"],"backgroundTag":"invalid-git-ref","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}