pcottle/learnGitBranching · error · GitError
' + ref + ' is not a branch
Error message
' + ref + ' is not a branch
What it means
assertIsBranch resolves the ref via engine.resolveID and throws if the object is missing or its type is not 'branch'. It means the command requires a local branch name but got a tag, commit SHA, remote-tracking ref, or nonexistent name.
Source
Thrown at src/js/git/commands.js:65
var assertNotCheckedOut = function(engine, ref) {
if (!engine.refs[ref]) {
return;
}
if (engine.HEAD.get('target') === engine.refs[ref]) {
throw new GitError({
msg: intl.todo(
'cannot fetch to ' + ref + ' when checked out on ' + ref
)
});
}
};
var assertIsBranch = function(engine, ref) {
assertIsRef(engine, ref);
var obj = engine.resolveID(ref);
if (!obj || obj.get('type') !== 'branch') {
throw new GitError({
msg: intl.todo(
ref + ' is not a branch'
)
});
}
};
var assertIsRemoteBranch = function(engine, ref) {
assertIsRef(engine, ref);
var obj = engine.resolveID(ref);
if (obj.get('type') !== 'branch' ||
!obj.getIsRemote()) {
throw new GitError({
msg: intl.todo(
ref + ' is not a remote branch'
)
});View on GitHub (pinned to 5b09d0ff96)
Solutions
- Verify the name with git branch / engine.getBranches()
- Drop the o/ prefix or use the local branch name
- If a tag was intended, use a command/option that accepts tags
Example fix
// before git push origin o/main // after git push origin main
Defensive patterns
Strategy: type-guard
Validate before calling
var obj = engine.resolveID(ref); if (!obj || obj.get('type') !== 'branch') return; Type guard
function isBranchRef(engine, ref) { var o = engine.resolveID(ref); return !!o && o.get('type') === 'branch'; } Prevention
- Offer only engine branch names in autocomplete
- Resolve and type-check refs before building commands
When it happens
Trigger: Commands whose config calls assertIsBranch, e.g. pushing/fetching with 'v1' (a tag) or 'o/main' or a raw commit id as the branch argument.
Common situations: Typo'd branch names; assuming remote-tracking branches (o/main) count as branches; passing tags where branches are required.
Related errors
- git-error-exist
- ' + ref + ' is not a remote branch
- ' + branchName + ' is not a branch!
- fatal: HEAD does not point to a branch
- bad-branch-name
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/dfa543bf802acc34.
Report an issue: GitHub.