# What does `git push origin --delete ""` do?

2 messages from 2021-02-23 to 2021-02-23. Participants: Tilman Vogel, Junio C Hamano.
Thread: https://gitlist.dev/t/55197

## Tilman Vogel, 2021-02-23 21:50

Subject: What does `git push origin --delete ""` do?
Message-ID: <CAAbQbbCAqbJhU05WSWD6HmHpAxLqs0LbFzQmKHNaDUg2kHkZBQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAAbQbbCAqbJhU05WSWD6HmHpAxLqs0LbFzQmKHNaDUg2kHkZBQ%40mail.gmail.com

```
Hi!

Because of an empty line in the input file, my script

cat remove.txt | sed 's/origin\///' | xargs -d '\n' git push origin --delete

executed (among other deletions) an implicit `git push origin --delete
""`. I wonder, what that one is supposed to do. I think, it should
produce an error just as `git push origin --delete` without a further
argument does but it doesn't. It seemed like instead, it tried to push
all my local branches to origin!? Is this something that should get
fixed?

Best regards,

Tilman

```

## Junio C Hamano, 2021-02-23 22:46

Subject: Re: What does `git push origin --delete ""` do?
Message-ID: <xmqqa6ru1jxg.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqa6ru1jxg.fsf%40gitster.g
In-Reply-To: <CAAbQbbCAqbJhU05WSWD6HmHpAxLqs0LbFzQmKHNaDUg2kHkZBQ@mail.gmail.com>

```
Tilman Vogel <tilman.vogel@web.de> writes:

> Because of an empty line in the input file, my script
>
> cat remove.txt | sed 's/origin\///' | xargs -d '\n' git push origin --delete
>
> executed (among other deletions) an implicit `git push origin --delete
> ""`. I wonder, what that one is supposed to do.

It is supposed to error out, but incorrectly and silently turns
itself into a "matching push".

This should fix it, I think (not even compiled tested).

 builtin/push.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git c/builtin/push.c w/builtin/push.c
index 03adb58602..194967ed79 100644
--- c/builtin/push.c
+++ w/builtin/push.c
@@ -115,7 +115,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
 			else
 				refspec_appendf(&rs, "refs/tags/%s", ref);
 		} else if (deleterefs) {
-			if (strchr(ref, ':'))
+			if (strchr(ref, ':') || !*ref)
 				die(_("--delete only accepts plain target ref names"));
 			refspec_appendf(&rs, ":%s", ref);
 		} else if (!strchr(ref, ':')) {

```
