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

Re: master^ is not a local branch -- huh?!?

From
Petr Baudis <pasky@suse.cz>
Date
Feb 1, 2010, 23:01 UTC
Message-ID
<20100201230150.GK9553@machine.or.cz>
In-Reply-To
<ron1-6F8B85.14520801022010@news.gmane.org>
On Mon, Feb 01, 2010 at 02:52:08PM -0800, Ron Garret wrote:
Show 22 quoted lines
> In article <87aavsu9b3.fsf@osv.gnss.ru>, Sergei Organov <osv@javad.com> 
> wrote:
> 
> > Junio C Hamano <gitster@pobox.com> writes:
> > > Steve Diver <squelch2@googlemail.com> writes:
> > 
> > [...]
> > 
> > > If read carefully (some may argue that it does not need a very careful
> > > reading to get it, though), this hints that "detached HEAD" state is a
> > > substitute for using a temporary branch, but it may not be strong
> > > enough.
> > 
> > For my rather fresh eye it looks more like unnamed (anonymous?) branch
> > than a temporary one. Doesn't detached HEAD behave exactly like a
> > regular HEAD but pointing to the tip of an unnamed branch?
> 
> I strongly concur with this.
> 
> And as long as I'm weighing in, it would also help to prevent confusion 
> if it were made clear that this unnamed branch doesn't actually come 
> into existence unless and until you do a commit.

That statement is not quite consistent with the Git model. A branch is a pointer. Detached HEAD is "unnamed" branch pointer (as in, you can refer to it by the default HEAD alias, but not by any other name). In this sense, the moment you create detached HEAD, you created the anonymous branch, and the moment you check out something else, it is gone in a wisp of smoke again.

The act of committing does not come into the picture at all. Committing is the act of saving a commit to the database and *updating* the current branch pointer to point at it. However, it does not affect what branch pointer is the current one. It is important to realize that:

	* Branches refer to commits.
	* Commits do not refer to branches!

That is, when you create a commit, it is not _tied_ to a particular branch. Thus, when you create a commit, you could not have created any branch, and creating a branch [pointer] is unrelated to creating any commits.

-- 
				Petr "Pasky" Baudis
If you can't see the value in jet powered ants you should turn in
your nerd card. -- Dunbal (464142)
Previous: Ron GarretNext: Nicolas Pitre
Message 5 of 24 in “Re: master^ is not a local branch -- huh?!?”
  1. Steve DiverFeb 1, 2010
  2. Junio C HamanoFeb 1, 2010
  3. Sergei OrganovFeb 1, 2010
  4. Ron GarretFeb 1, 2010
  5. Petr BaudisFeb 1, 2010
  6. Nicolas PitreFeb 1, 2010
  7. Junio C HamanoFeb 1, 2010
  8. Ron GarretFeb 1, 2010
  9. Petr BaudisFeb 2, 2010
  10. Ron GarretFeb 2, 2010
  11. Junio C HamanoFeb 2, 2010
  12. Ron GarretFeb 2, 2010
  13. J. Bruce FieldsFeb 2, 2010
  14. Ron GarretFeb 2, 2010
  15. J. Bruce FieldsFeb 3, 2010
  16. Nicolas PitreFeb 2, 2010
  17. Ron GarretFeb 2, 2010
  18. Nicolas PitreFeb 2, 2010
  19. tytso@mit.eduFeb 2, 2010
  20. Junio C HamanoFeb 2, 2010
  21. Junio C HamanoFeb 2, 2010
  22. Nicolas PitreFeb 1, 2010
  23. Jay SoffianFeb 1, 2010
  24. Steve DiverFeb 1, 2010

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.