pcottle/learnGitBranching · error · GitError

cannot delete branch ' + options.destination + ' which doesn

Error message

cannot delete branch ' + options.destination + ' which doesn't exist

What it means

When deleting via an empty-source refspec (`:branch`), git checks the destination branch exists on the remote. Here origin.resolveID(destination) fails to find the branch on the simulated remote, so deletion is refused. Note: the message interpolates options.destination which may be stale — a cosmetic bug worth knowing.

Source

Thrown at src/js/git/commands.js:999

              '--delete only accepts plain target ref names'
            )
          });
        }

        // transform delete target ref to delete colon refspec
        firstArg = ":"+firstArg;
      }

      if (firstArg && isColonRefspec(firstArg)) {
        if (firstArg[0] == '+') {
          force = true;
          firstArg = firstArg.substr(1);
        }
        var refspecParts = firstArg.split(':');
        source = refspecParts[0];
        destination = validateBranchName(engine, refspecParts[1]);
        if (source === "" && !engine.origin.resolveID(destination)) {
          throw new GitError({
            msg: intl.todo(
              'cannot delete branch ' + options.destination + ' which doesn\'t exist'
            )
          });
        }
      } else {
        if (firstArg) {
          // we are using this arg as destination AND source. the dest branch
          // can be created on demand but we at least need this to be a source
          // locally otherwise we will fail
          assertIsRef(engine, firstArg);
          sourceObj = engine.resolveID(firstArg);
        } else {
          // since they have not specified a source or destination, then
          // we source from the branch we are on (or HEAD)
          sourceObj = engine.getOneBeforeCommit('HEAD');
        }
        source = sourceObj.get('id');

View on GitHub (pinned to 5b09d0ff96)

Solutions

  1. List remote branches first: `git branch -r` to confirm the name
  2. Fetch/re-clone so o/ tracking refs reflect the remote state
  3. If already deleted, no action is needed

Example fix

// before
git push origin :feature-x  // feature-x not on origin
// after
git branch -r               // verify, then
git push origin :feature-x
Defensive patterns

Strategy: validation

Validate before calling

if (engine.origin.resolveID(destination)) { /* safe to delete */ }

Prevention

When it happens

Trigger: `git push origin :<branch>` (or --delete <branch>) where <branch> does not exist on origin; e.g. it was never pushed or already deleted.

Common situations: Trying to delete a remote branch that was already removed; deleting a local-only branch name that was never pushed.

Related errors


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