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

  1. Verify the name with git branch / engine.getBranches()
  2. Drop the o/ prefix or use the local branch name
  3. 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

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


AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27). Data as JSON: /api/errors/dfa543bf802acc34. Report an issue: GitHub.