git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
EAErlend Aasland <erlend-a@innova.no>
Date
Feb 16, 2022, 23:06 UTC
Message-ID
<400A4D37-74EA-4F3B-BA3B-99FFDAE3CB3C@innova.no>
In-Reply-To
<00720bfb-c7b7-aaf2-e846-19b08d7b9cf4@sunshineco.com>
Show 5 quoted lines
> On 16 Feb 2022, at 20:03, Eric Sunshine <sunshine@sunshineco.com> wrote:
> 
> 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/20200501222227.GE41612@syl.local/T/
Thanks for the heads-up regarding previous discussions, Eric.

AFAIK, switch/checkout, rebase, and merge all use "-" as a shortcut to the "last branch", so for me, it made sense with similar semantics when deleting a branch. I understand the concern regarding "destructive operations", but deleting a branch is not comparable to, for example, deleting a file. Deleting a branch is "soft destructive"; unless *explicitly* silenced, git kindly tells us which ref we can use to immediately recreate our branch:

$ git branch -D - # oops, shouldn't have done that! Deleted branch stuff (was 580cd9ab29). $ git switch -c stuff 580cd9ab29

Until now, I've just been using the @{-1} notation, but - is very much faster to type ;)

There are no new arguments pro this feature, so I guess the conclusion from 2020 still stands :)

E
Previous: Junio C HamanoNext: Eric Sunshine
Message 5 of 11 in “branch: delete now accepts '-' as branch name”
  1. branch: delete now accepts '-' as branch nameErlend Egeberg Aasland via GitGitGadget, Feb 16, 2022
  2. Junio C HamanoFeb 16, 2022
  3. Eric SunshineFeb 16, 2022
  4. Junio C HamanoFeb 16, 2022
  5. Erlend AaslandFeb 16, 2022
  6. Eric SunshineFeb 17, 2022
  7. Junio C HamanoFeb 17, 2022
  8. Ævar Arnfjörð BjarmasonFeb 21, 2022
  9. Junio C HamanoFeb 21, 2022
  10. Ævar Arnfjörð BjarmasonFeb 21, 2022
  11. Erlend AaslandFeb 22, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.