{"record":{"id":"675669fbf990ee50","repo":"pcottle/learnGitBranching","slug":"fatal-not-a-branch","errorCode":null,"errorMessage":"fatal: not a branch: ","messagePattern":"fatal: not a branch: ","errorType":"validation","errorClass":"GitError","httpStatus":null,"severity":"error","filePath":"src/js/git/index.js","lineNumber":2815,"sourceCode":"  }\n\n  if (numAway.length === 0) {\n    throw new CommandResult({\n      msg: foundTag\n    });\n  }\n\n  // then join\n  throw new CommandResult({\n    msg: foundTag + '-' + numAway.length + '-g' + startCommit.get('id')\n  });\n};\n\nGitEngine.prototype.renameBranch = function(oldName, newName, force) {\n  var target = this.resolveID(oldName);\n\n  if (!target || target.get('type') !== 'branch') {\n    throw new GitError({\n      msg: intl.todo('fatal: not a branch: ' + oldName)\n    });\n  }\n\n  if (target.getIsRemote()) {\n    throw new GitError({\n      msg: intl.str('git-error-remote-branch')\n    });\n  }\n\n  newName = this.validateBranchName(newName);\n\n  if (this.doesRefExist(newName)) {\n    if (!force) {\n      throw new GitError({\n        msg: intl.todo(\"fatal: A branch named '\" + newName + \"' already exists.\")\n      });\n    }","sourceCodeStart":2797,"sourceCodeEnd":2833,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/index.js#L2797-L2833","documentation":"Thrown by the force-capable renameBranch(oldName, newName, force) when resolveID(oldName) returns null or something that is not a branch (tag, commit, HEAD). Mirrors git's 'fatal: not a branch' when branch -m is given a non-branch ref. Note the message is built with intl.todo so it is currently untranslated.","triggerScenarios":"renameBranch(name,...) where the first arg fails to resolve or resolves to a non-branch ref — e.g. renaming a tag, a commit sha, or a misspelled branch name.","commonSituations":"Typos in the source branch name; passing a tag or commit id to branch -m; scripted renames that assume a branch exists after it was deleted.","solutions":["Confirm the ref exists and is a local branch (this.resolveID(name).get('type') === 'branch') before renaming","Fix typos in the branch name","For tags/commits, use the appropriate command instead of rename"],"exampleFix":"// before\nengine.renameBranch('featr', 'feature'); // typo\n// after\nengine.renameBranch('feat', 'feature');","handlingStrategy":"type-guard","validationCode":"var t = engine.resolveID(oldName);\nif (!t || t.get('type') !== 'branch') { /* bail or fix name */ }","typeGuard":"function isBranch(engine, name) { var r = engine.resolveID(name); return !!r && r.get('type') === 'branch'; }","tryCatchPattern":"try { engine.renameBranch(a, b, f); } catch (e) { if (e instanceof GitError && /^fatal: not a branch/.test(e.msg)) { /* handle */ } else throw e; }","preventionTips":["Guard the old name resolves to a branch before rename","Avoid passing tags/shas"],"tags":["git","branch","rename","ref-validation","untranslated"],"backgroundTag":"invalid-git-ref","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}