threads / discuss / 25179

more useful set-upstream

Subject: more useful set-upstream

## tl;dr

2 messages between Sep 21, 2010 and Sep 21, 2010.

replies: 1people: 2as markdown or json

Ramana Kumar· Sep 21, 2010, 08:55 UTC · lore
Is there a better way to achieve the functionality of this alias?
  set-upstream = "!sh -c 'current=$(git symbolic-ref HEAD); git branch
\"$current\" --set-upstream \"$1\"/$(basename $current)' -"
(forgive me if stupid gmail word wrapped that line)
This allows me to write
$ git set-upstream origin
instead of
$ git branch <current branch> --set-upstream origin/<current branch>

which is a pain to write for several reasons: I have to remember the current branch name, that name might be long, and shell autocomplete doesn't know about --set-upstream yet so won't complete the second occurrence.

Having a dedicated script (or git command) rather than an alias would allow
greater functionality like:
 - automatically pick the remote name if there's only one remote,
 - a flag to automatically set upstream on all branches (that having
   matching remotes)

I don't understand why all my branches haven't automatically had the right upstream set anyway - am I missing some configuration of pull and push?

Matthieu Moy· Sep 21, 2010, 09:30 UTC · re: Ramana Kumar · lore

Re: more useful set-upstream

Ramana Kumar <ramana.kumar@gmail.com> writes:
> I don't understand why all my branches haven't automatically had the right
> upstream set anyway - am I missing some configuration of pull and
> push?
If you keep it simple, they should:
* git clone wherever => checks out the default branch, and sets the
  upstream for it.
* git checkout foo => if foo doesn't exist, and <remote>/foo exists,
  foo is created and upstream is set to <remote>/foo (that's rather
  recent)

But we could probably have a better way to set the upstream after the fact when the initialisation magic didn't do its job.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads