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

Bug: git branch -D can be used to delete branch which is currently checked out

From
Marcus Kida <marcus.kida@gmail.com>
Date
Mar 10, 2016, 08:20 UTC
Message-ID
<CE5AE06C-0909-414E-B901-7CCF3A259465@gmail.com>
Testes on: 
Mac OS X 10.11.3 (El Capitan) using Git 2.6.4
Issue:
git branch -D can be used to delete branch which is currently checked out
Steps to reproduce:
inside a git repository:
$ git checkout -b feature/myAwesomeFeature
-> you end up in feature/myAwesomeFeature branch
$ git checkout FEATURE/myAwesomeFeature
-> you end up in FEATURE/myAwesomeFeature branch
$ git branch -D feature/myAwesomeFeature branch
-> BOOM you just deleted the branch you were at. Congrats you repo is dirty again.
Actual behaviour:
It seems like checking out / deleting branches is case insensitive thus you can delete a branch you are on by just using a different capitalisation when specifying the branch to delete.
Expected behaviour:
error: Cannot delete the branch 'FEATURE/myAwesomeFeature' which you are currently on.
Thank you, please don't hesitate to contact me in case you need more info or if this has already been fixed in the meantime.

Cheers, Marcus

Next: Junio C Hamano
Message 1 of 4 in “Bug: git branch -D can be used to delete branch which is currently checked out”
  1. Marcus KidaMar 10, 2016
  2. Junio C HamanoMar 10, 2016
  3. Junio C HamanoMar 10, 2016
  4. Marcus KidaMar 10, 2016

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.