# more useful set-upstream

2 messages from 2010-09-21 to 2010-09-21. Participants: Ramana Kumar, Matthieu Moy.
Thread: https://gitlist.dev/t/25179

## Ramana Kumar, 2010-09-21 08:55

Subject: more useful set-upstream
Message-ID: <AANLkTi=c51u=pQ3TLt3YE54mbwy8AqRb2rcsatEVo2U5@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3Dc51u%3DpQ3TLt3YE54mbwy8AqRb2rcsatEVo2U5%40mail.gmail.com

```
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, 2010-09-21 09:30

Subject: Re: more useful set-upstream
Message-ID: <vpqfwx3phou.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqfwx3phou.fsf%40bauges.imag.fr
In-Reply-To: <AANLkTi=c51u=pQ3TLt3YE54mbwy8AqRb2rcsatEVo2U5@mail.gmail.com>

```
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/

```
