git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:28 UTC

Re: git branch -M" regression in 1.7.7?

From
Conrad Irwin <conrad.irwin@gmail.com>
Date
Nov 26, 2011, 07:05 UTC
Message-ID
<CAOTq_pv4dyAkbqye+diK9mTTsrTg9OKg0tExKcfDgs8RfiTwTQ@mail.gmail.com>
In-Reply-To
<20111126023002.GA17652@elie.hsd1.il.comcast.net>
On Fri, Nov 25, 2011 at 6:30 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> A reproduction recipe (preferrably in the form of a patch to
> t/t3200-branch.sh would be welcome.

Sent in a separate email. Feel free to add a "Tested-by:" header to your patch if you want :).

Show 19 quoted lines
>
> -- >8 --
> Subject: treat "git branch -M master master" as a no-op again
>
> Before v1.7.7-rc2~1^2~2 (Prevent force-updating of the current branch,
> 2011-08-20), commands like "git branch -M topic master" could be used
> even when "master" was the current branch, with the somewhat
> counterintuitive result that HEAD would point to some place new while
> the index and worktree kept the content of the old commit.  This is
> not a very sensible operation and the result is what almost nobody
> would expect, so erroring out in this case was a good change.
>
> However, there is one exception to the "it's usually not obvious what
> it would mean to overwrite the current branch by another one" rule.
> Namely:
>
>        git branch -M master master
>
> is clearly meant to be a no-op, even if you are on the master branch.
Agreed. I thought after reading your patch about making it just do:
    if (!strcmp(oldname, newname))
        exit(0);

but I guess it would then not mark an entry in the reflog that people could be relying on...

> +       clobber_head_ok = !strcmp(oldname, newname);
> +
> +       validate_new_branchname(newname, &newref, force, clobber_head_ok);
This looks ok, and will be improvable if the NEEDSWORK in branch.h is done.

The other thing I wonder is whether "git checkout -B master HEAD" or "git branch -f master master" should have the same short-cut?

Conrad
Previous: Jonathan NiederNext: Jonathan Nieder
Message 5 of 9 in “git branch -M" regression in 1.7.7?”
  1. ☂Josh Chia (谢任中)Nov 26, 2011
  2. Jonathan NiederNov 26, 2011
  3. Test renaming a branch to itselfConrad Irwin, Nov 26, 2011
  4. Jonathan NiederNov 26, 2011
  5. Conrad IrwinNov 26, 2011
  6. Jonathan NiederNov 26, 2011
  7. Junio C HamanoNov 26, 2011
  8. Andreas SchwabNov 26, 2011
  9. Junio C HamanoNov 28, 2011

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.