Subject: Re: [PATCH] branch: delete now accepts '-' as branch name

From: Junio C Hamano <[email-masked]>
Date: Wed, 16 Feb 2022 11:41:52 -0800

Eric Sunshine <[email-masked]> writes:

> On 2/16/22 11:54 AM, Junio C Hamano wrote:
>> From: "Erlend E. Aasland" <[email-masked]>
>>> This makes it easy to get rid of short-lived branches:
>>>
>>> $ git switch -c experiment
>>> $ git switch -
>>> $ git branch -D -
>> Or you can use @{-1} directly.  Or short-lived experiment can
>> directly be done on HEAD without any branch ;-)
>> Thanks for trying to make Git better.
>
> Patches implementing this behavior for `git branch -D` have been
> submitted previously but were rejected (if I recall correctly) since 
> "delete" is a destructive operation, unlike other cases in which `-`
> is accepted. A relatively recent submission and ensuing discussion is
> at [1].
>
> [1]: https://lore.kernel.org/git/[email-masked]/T/

I think the thread around <[email-masked]> is what you
have in mind as the origin of

 * "-" usually stands for "read from standard input" and using it to
   mean "the previous branch" is a source of confusion, and cannot
   be defended with the excuse of "'cd -' is used to go back to
   where we were" when the command is not going back to that branch
   (i.e. not "checkout -" or "switch -").

 * it is doubly dubious to make it easy to type "-" to cause
   something destructive.

 * on the other hand, since "checkout -" already makes "-" as a
   synonym to "@{-1}", not supporting it elsewhere may appear
   inconsistent.

I personally am sympathetic to the first point, but not that
sympathetic to the second one.  We made it worse since then by
accepting "merge -", which is not about going back, though.