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

Case sensitivity when deleting a checked out branch

From
GWguillaume weybrecht <guillaume.weybrecht@gmail.com>
Date
Mar 8, 2018, 19:57 UTC
Message-ID
<420c2cd9-c38b-8f90-0fec-e070b19efb49@gmail.com>
Hello,

I came across an odd behavior in Git related to case sensitivity when deleting a checked out branch. I was not able to find much information about it.

$ git checkout -b foo $ git branch -d foo       # error: Cannot delete branch 'foo' checked out => this is expected, nothing happens since you are on branch 'foo' $ git branch -d Foo       # Deleted branch Foo => this is not expected, Git removed 'foo' from .git/refs/heads

Git removed the 'foo' file from .git/refs/heads, but did not update the .git/HEAD file which still contains "ref: refs/heads/foo".

In fact, everything looks like a "git checkout --orphan foo": $ git status              # On branch foo. No commits yet (the working tree is staged) $ git log                 # fatal: your current branch 'foo' does not have any commits yet $ git rev-parse HEAD --   # fatal: bad revision 'HEAD' $ git fsck                # notice: HEAD points to an unborn branch (foo)

You can run "git checkout <other_branch>" to get back on your feet as you would after "git checkout --orphan foo".

The thing is, you get there unexpectedly without any warning, just with a case sensitivity mistake in "git branch -d". Even it is seems unlikely to happen, someone ran into this at my job.

Tested on Windows 2.15.1.windows.2 and 2.16.2.windows.1, and on Mac OS (I think it was a 2.14 version).

Best regards, Guillaume

--- L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast. https://www.avast.com/antivirus

Message 1 of 1 in “Case sensitivity when deleting a checked out branch”
  1. guillaume weybrechtMar 8, 2018

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.