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

branch --set-upstream considered harmful

From
Jay Soffian <jaysoffian@gmail.com>
Date
Jun 6, 2010, 19:21 UTC
Message-ID
<AANLkTiln_xxnF-e33YA7kkfbBBcBMd40xag8JTW0eqws@mail.gmail.com>

Say I have an existing branch and it doesn't have a tracking config. (My local users often just do "checkout -b topic" instead of "checkout -b topic origin/master".)

I would naively expect this to work, while on that branch:
  (topic)$ git branch --set-upstream origin/master
But, um no:
  (topic)$ git branch --set-upstream origin/master
  Branch origin/master set up to track local branch topic.
Doh!
Well, maybe this works:
  (topic)$ git branch --set-upstream origin/master topic
  Branch origin/master set up to track local branch topic.
Doh!^2

Well, maybe we can say "HEAD" since that seems to mean "the current branch" everywhere else in gitland:

  (topic)$ git branch --set-upstream HEAD origin/master
  Branch HEAD set up to track remote branch master from origin.
(Aside, being able to create a branch named HEAD is surely a bug, right?)

Finally after exhausting all other possibilities (or finally making sense of --set-upstream in the man page), we realize:

  (topic)$ git branch --set-upstream topic origin/master
  Branch topic set up to track remote branch master from origin.
Trying to make myself feel better, I realize that this works:
  (topic)$ git branch topic --set-upstream origin/master

So here's how I'm thinking about fixing it, but maybe I'm just making it even more confusing. What say you:

  (topic)$ git branch --set-upstream=origin/master
  Branch topic set up to track remote branch master from origin.

--track would be similarly enhanced, which allows a little more flexibility in creating a branch thusly:

  $ git branch --track=origin/master topic

Which creates topic, starting from HEAD, but tracking origin/master. (And I'd do the same for checkout's --track option.)

I recognize that having both positional and non-positional forms of --track/--set-upstream may be confusing, but I think it's less confusing than set-upstream's current semantics, I'm loathe to introduce yet another option, and I don't want to break backward compatibility.

Flames?
j.
Next: Tay Ray Chuan
Message 1 of 6 in “branch --set-upstream considered harmful”
  1. Jay SoffianJun 6, 2010
  2. Tay Ray ChuanJun 7, 2010
  3. Jay SoffianJun 7, 2010
  4. Thomas RastJun 7, 2010
  5. Jay SoffianJun 7, 2010
  6. Michael J GruberJun 7, 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.