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

Re: [PATCH 1/3] branch: introduce --set-upstream-to

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 10, 2012, 23:13 UTC
Message-ID
<7vehojgqgk.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120710210901.GI8439@burratino>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 7 quoted lines
> [someone should have]
> | suggested an alternative syntax that avoids the mistake you quoted
> | above, perhaps something like:
> |
> | 	git branch --set-upstream-to=origin/master [HEAD]
>
> with which I disagree.
You can think of it this way.

"git branch" can not only _create_ a new branch (or list existing ones, but that is another entirely different mode), but also can be used to set attributes to an existing branch. Imagine a new option, say --set-description, to replace branch.frotz.description, for example. It would be used like this:

	$ git branch --set-description='add frotz feature' frotz

to set the description for the 'frotz' branch (i.e. the above would set branch.frotz.description), and we default to HEAD if 'frotz' is missing from the command line. "git branch --option [<branch>]" is about manipulating the branch, and we default the target of manipulation to HEAD.

"upstream" is just another kind of attribute for the branch being manipulated, whose value happens to be a branch name.

The mistake was that --set-upstream was coded by piggybacking the existing --track implementation where a new branch was created, and in that codepath, "git branch <name1> [<name2>]" creates <name1> while defaulting a missing <name2> to HEAD.

Creating a new branch that is forked from the current HEAD is an often useful thing to do, so defaulting a missing <name2> (aka "start-point") to HEAD is very sensible, but reconfiguring a named branch <name1> to integrate with the current branch is much less useful than the other way around. One major reason why it is so is because you would more likely set any branch to integrate with a remote tracking branch (rather than a local branch) and by definition your HEAD cannot be a remote tracking branch.

It makes it worse that you would often want to reconfigure the current branch; for the purpose of reconfiguring a branch <name1> to integrate with something else <name2>, it is much more likely that you want a missing <name1> to default to HEAD, not the other way around to default a missing <name2> to HEAD, which is useful for branch creation.

But switching which missing argument gets default based on what options are used is insane.

If the very original "create this new branch starting at that point" were spelled like this

	$ git branch [--start-point=<name2>] <name1>

and a missing <name2> defaulted to HEAD, it probably would have been better. It would have made it very unlikely to tempt anybody to hack the --set-upstream option into the system with the wrong parameter order if such a command line convention was in place.

If anything, it could be a sensible longer-term direction to a more intuitive UI to deprecate the two-name format and make the creation to be specified with an explicit --start-point option with an argument (which defaults to HEAD), but I think that falls into the "if I were reinventing git without existing userbase in 2005" category and it is too late for that.

Previous: Jonathan NiederNext: Jonathan Nieder
Message 10 of 29 in “A better way of handling upstream information in git-branch”
  1. 0/3 A better way of handling upstream information in git-branchCarlos Martín Nieto, Jul 10, 2012
  2. 1/3 branch: introduce --set-upstream-toCarlos Martín Nieto, Jul 10, 2012
  3. Matthieu MoyJul 10, 2012
  4. Junio C HamanoJul 10, 2012
  5. Jonathan NiederJul 10, 2012
  6. Junio C HamanoJul 10, 2012
  7. Jonathan NiederJul 10, 2012
  8. Junio C HamanoJul 10, 2012
  9. Jonathan NiederJul 10, 2012
  10. Junio C HamanoJul 10, 2012
  11. Jonathan NiederJul 10, 2012
  12. Junio C HamanoJul 11, 2012
  13. Jonathan NiederJul 11, 2012
  14. Miles BaderJul 12, 2012
  15. Junio C HamanoJul 12, 2012
  16. 2/3 branch: suggest how to undo a --set-upstream when given one branchCarlos Martín Nieto, Jul 10, 2012
  17. Matthieu MoyJul 10, 2012
  18. Carlos Martín NietoJul 11, 2012
  19. Junio C HamanoJul 10, 2012
  20. Carlos Martín NietoJul 11, 2012
  21. Jonathan NiederJul 10, 2012
  22. Junio C HamanoJul 10, 2012
  23. Jonathan NiederJul 10, 2012
  24. Carlos Martín NietoJul 11, 2012
  25. 3/3 branch: add --unset-upstream optionCarlos Martín Nieto, Jul 10, 2012
  26. Junio C HamanoJul 10, 2012
  27. Carlos Martín NietoJul 11, 2012
  28. Junio C HamanoJul 11, 2012
  29. Carlos Martín NietoJul 12, 2012

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.