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
- List remote branches first: `git branch -r` to confirm the name
- Fetch/re-clone so o/ tracking refs reflect the remote state
- 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
- Check `git branch -r` (engine.origin refs) before remote deletes
- Fetch to sync o/ refs after out-of-band changes
- Skip delete if the branch is already gone
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
- --delete doesn't make sense without any refs
- --delete only accepts plain target ref names
- You cannot delete main branch on remote!
- ' + branchName + ' is not a branch!
- ' + branchName + ' is not a remote tracking branch! I don't
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/3281b2a690b15168.
Report an issue: GitHub.