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

Re: [PATCH] branch: add -u as a shortcut for --set-upstream

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 6, 2012, 15:32 UTC
Message-ID
<20120706153239.GA29362@burratino>
In-Reply-To
<1341475035-14310-1-git-send-email-cmn@elego.de>
Hi Carlos,
Carlos Martín Nieto wrote:
> Add this shortcut just like git-push has it.
[...]
Show 9 quoted lines
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -724,7 +724,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  		OPT__QUIET(&quiet, "suppress informational messages"),
>  		OPT_SET_INT('t', "track",  &track, "set up tracking mode (see git-pull(1))",
>  			BRANCH_TRACK_EXPLICIT),
> -		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
> +		OPT_SET_INT('u', "set-upstream",  &track, "change upstream info",
>  			BRANCH_TRACK_OVERRIDE),
I think this is a bad idea.  The --set-upstream option is confusing:
	$ git branch --set-upstream=foo
	error: option 'set-upstream' takes no value
	$ ???

-u to set the corresponding upstream branch at the same time as creating a branch, analagous to "git push -u" might seem intuitive:

	# create foo branch, setting its upstream at the same time
	git branch -u foo origin/foo
But that is what --track does and is not what --set-upstream is for.

Unlike --track, I don't think --set-upstream is a common enough operation to deserve a one-letter synonym.

Instead, I'd suggest the following changes:
 1) Add support for
	# change upstream info
	git branch --set-upstream=origin/foo foo
    for existing branches only.
 2) Introduce an --unset-upstream option which removes the
    "corresponding upstream branch" configuration for an existing
    branch.
 3) Warn on
	# acts just like --track
	git branch --set-upstream foo origin/foo
    for branches that do not exist yet.  Plan to make this a hard
    error in the future.
 4) Warn on
	# sets upstream for "foo" to the current branch
	git branch --set-upstream foo
    and plan to make it a hard error in the future.
 5) Warn on
	git branch --set-upstream origin/foo foo
  which is almost certainly a typo for
	git branch --set-upstream=origin/foo foo
 6) Perhaps, make -u a synonym for -t for consistency with "git push".

What do you think? Jonathan

Previous: Carlos Martín NietoNext: Carlos Martín Nieto
Message 2 of 3 in “branch: add -u as a shortcut for --set-upstream”
  1. branch: add -u as a shortcut for --set-upstreamCarlos Martín Nieto, Jul 5, 2012
  2. Jonathan NiederJul 6, 2012
  3. Carlos Martín NietoJul 8, 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.