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

Re: Bug in `git branch --delete main` when on other orphan branch

From
Martin von Zweigbergk <martinvonz@google.com>
Date
Nov 1, 2022, 15:31 UTC
Message-ID
<CAESOdVDmLxj2chGZzJYPjD6bw4XqWjjrPesc2ZCiE8JLPenADw@mail.gmail.com>
In-Reply-To
<Y2DxxZAFbN8juHY6@coredump.intra.peff.net>
On Tue, Nov 1, 2022 at 3:15 AM Jeff King <peff@peff.net> wrote:
Show 22 quoted lines
>
> On Fri, Oct 28, 2022 at 10:46:37PM -0700, Martin von Zweigbergk wrote:
>
> > I did this:
> > git init test
> > cd test
> > echo a > file
> > git add file
> > git commit -m a
> > git checkout --orphan other
> > git branch --delete main
> >
> > The last command fails with:
> > fatal: Couldn't look up commit object for HEAD
> >
> > That's a bug, right? I can of course work around it with `rm
> > .git/refs/heads/main`.
>
> Sort of. This is part of the "is the thing we are deleting merged into
> HEAD" check. It tries to look up the HEAD and calls die() when it can't.
> The more correct thing, I think, would be for it to just return "nope,
> there is no HEAD so nothing is merged into it".
Ah, so that's what it was about. Thanks for looking into it!
> And in the meantime, hopefully you noticed that "-f" is a better
> workaround than manually deleting the refs file. :)

Nope, because I had no idea it was something that could be first. Also, this was just in a script to reproduce an unrelated (non-Git) bug, so my hacky workaround was okay :)

Thanks!
Previous: Jeff KingNext: Taylor Blau
Message 3 of 12 in “Bug in `git branch --delete main` when on other orphan branch”
  1. Martin von ZweigbergkOct 29, 2022
  2. Jeff KingNov 1, 2022
  3. Martin von ZweigbergkNov 1, 2022
  4. Taylor BlauNov 1, 2022
  5. Taylor BlauNov 1, 2022
  6. Jeff KingNov 1, 2022
  7. Taylor BlauNov 2, 2022
  8. branch: gracefully handle '-d' on detached HEADTaylor Blau, Nov 1, 2022
  9. branch: gracefully handle '-d' on orphan HEADJeff King, Nov 2, 2022
  10. Rubén JustoNov 4, 2022
  11. Jeff KingNov 4, 2022
  12. Rubén JustoNov 6, 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.