pcottle/learnGitBranching · error · GitError

--delete only accepts plain target ref names

Error message

--delete only accepts plain target ref names

What it means

`git push --delete` only accepts a plain ref name, not a full refspec like `src:dst`. If the first argument contains a colon (isColonRefspec), the app rejects it just like real git.

Source

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

        ? option.concat(generalArgs)
        : generalArgs.concat(option);
      }

      command.twoArgsForOrigin(generalArgs);
      assertOriginSpecified(generalArgs);
      var firstArg = generalArgs[1];

      if(isDelete) {
        if(!firstArg) {
          throw new GitError({
            msg: intl.todo(
              '--delete doesn\'t make sense without any refs'
            )
          });
        }

        if(isColonRefspec(firstArg)) {
          throw new GitError({
            msg: intl.todo(
              '--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]);

View on GitHub (pinned to 5b09d0ff96)

Solutions

  1. Pass a plain branch name: `git push origin --delete foo`
  2. For refspec deletion use `git push origin :foo` without --delete

Example fix

// before
git push origin --delete foo:bar
// after
git push origin --delete foo
Defensive patterns

Strategy: validation

Validate before calling

function isColonRefspec(s) { return s.indexOf(':') !== -1; }
if (!isColonRefspec(ref)) { /* safe with --delete */ }

Type guard

function isValidDeleteTarget(s){ return /^[\w.\/-]+$/.test(s) && s.indexOf(':') === -1; }

Prevention

When it happens

Trigger: `git push origin --delete foo:bar` or any colon-containing refspec combined with --delete/-d.

Common situations: Mixing refspec syntax (used for force/normal pushes) with deletion syntax; muscle memory from `git push origin :branch`.

Related errors


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