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

Re: [1.8.0] git checkout refs/heads/foo checks out branch foo

From
Jeff King <peff@peff.net>
Date
Feb 7, 2011, 20:59 UTC
Message-ID
<20110207205934.GD13461@sigill.intra.peff.net>
In-Reply-To
<alpine.DEB.1.10.1102062234010.3788@debian>
On Mon, Feb 07, 2011 at 06:01:51AM -0500, Martin von Zweigbergk wrote:
Show 8 quoted lines
> 'git checkout refs/heads/foo' (or 'git checkout heads/foo' for that
> matter) does not check out the branch, but instead detaches HEAD at
> foo. This is quite counter-intuitive (at least to me) and the same
> functionality can be achieved by using e.g. foo~0. Change the behavior
> so that the branch is actually checked out. This also applies to
> e.g. 'git rebase master refs/heads/topic', which currently rebases a
> detached HEAD. There are probably other examples as well that I'm not
> aware of.

I have seen that behavior claimed as intentional, but I agree it is unintuitive. In most other places referring to a ref by a short name or a fully qualified name is equivalent (except with respect to disambiguating short names, of course).

> Existing scripts may depend on the current behavior. It seems unlikely
> that many users depend on it. Most likely, they use foo~0 or foo^0
> instead.

As cool and clever as the foo^0 behavior is once you understand it, I think it is a horribly confusing thing for non-experts. As part of this proposal, should we perhaps offer "git checkout --detach" as the easy-on-the-eyes way of intentionally detaching?

-Peff
Previous: Junio C HamanoNext: Sverre Rabbelier
Message 3 of 18 in “[1.8.0] git checkout refs/heads/foo checks out branch foo”
  1. Martin von ZweigbergkFeb 7, 2011
  2. Junio C HamanoFeb 7, 2011
  3. Jeff KingFeb 7, 2011
  4. Sverre RabbelierFeb 7, 2011
  5. Jonathan NiederFeb 7, 2011
  6. Junio C HamanoFeb 7, 2011
  7. Jeff KingFeb 7, 2011
  8. Jonathan NiederFeb 8, 2011
  9. Jeff KingFeb 8, 2011
  10. Martin von ZweigbergkFeb 8, 2011
  11. checkout: introduce --detach synonym for "git checkout foo^{commit}"Jonathan Nieder, Feb 8, 2011
  12. Jonathan NiederFeb 8, 2011
  13. 0/3 checkout: introduce --detach synonym for "git checkout foo^{commit}"Jonathan Nieder, Feb 8, 2011
  14. 1/3 checkout: split off a function to peel away branchname argJonathan Nieder, Feb 8, 2011
  15. 2/3 checkout: introduce --detach synonym for "git checkout foo^{commit}"Jonathan Nieder, Feb 8, 2011
  16. 3/3 checkout: rearrange update_refs_for_switch for clarityJonathan Nieder, Feb 8, 2011
  17. Heiko VoigtFeb 7, 2011
  18. Martin von ZweigbergkFeb 8, 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.