pcottle/learnGitBranching · error · GitError
fatal: not a branch: ' + oldName
Error message
fatal: not a branch: ' + oldName
What it means
Duplicate of error 65: the 'fatal: not a branch: <name>' GitError thrown by renameBranch when the old name does not resolve to a branch. The listed SOURCE message string is just the expression used to build the message; the condition is !target || target.get('type') !== 'branch'.
Source
Thrown at src/js/git/index.js:2821
}
// then join
throw new CommandResult({
msg: foundTag + '-' + numAway.length + '-g' + startCommit.get('id')
});
};
GitEngine.prototype.renameBranch = function(oldName, newName, force) {
var target = this.resolveID(oldName);
if (!target || target.get('type') !== 'branch') {
throw new GitError({
msg: intl.todo('fatal: not a branch: ' + oldName)
});
}
if (target.getIsRemote()) {
throw new GitError({
msg: intl.str('git-error-remote-branch')
});
}
newName = this.validateBranchName(newName);
if (this.doesRefExist(newName)) {
if (!force) {
throw new GitError({
msg: intl.todo("fatal: A branch named '" + newName + "' already exists.")
});
}
var existing = this.resolveID(newName);
if (existing.get('type') !== 'branch') {
throw new GitError({
msg: intl.str('git-error-options')
});
}View on GitHub (pinned to 5b09d0ff96)
Solutions
- Validate the ref type before calling renameBranch
- Correct the branch name
- Delete-then-create the branch if the intent was to move a non-branch ref
Defensive patterns
Strategy: validation
Validate before calling
var t = engine.resolveID(oldName); if (!t || t.get('type') !== 'branch') return; Type guard
function isBranch(engine, name) { var r = engine.resolveID(name); return !!r && r.get('type') === 'branch'; } Prevention
- Validate ref type first
- Double-check spelling of branch names
When it happens
Trigger: Same as 65: renameBranch with an oldName that is null, a tag, a commit, or otherwise not a branch ref.
Common situations: Misspelled branch names, renaming tags, passing HEAD.
Related errors
- git-error-branch
- fatal: not a branch:
- fatal: HEAD does not point to a branch
- fatal: A branch named ' + newName + ' already exists.
- ' + ref + ' is not a branch
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/af0422c4d22f6627.
Report an issue: GitHub.