# get-upstream

7 messages from 2010-09-23 to 2010-09-23. Participants: Ramana Kumar, Pat Notz, Jeff King.
Thread: https://gitlist.dev/t/25203

## Ramana Kumar, 2010-09-23 03:46

Subject: get-upstream
Message-ID: <AANLkTikqJmsUo53dRngXcWsoEfcFzLQ-J1V5oZOGUL03@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikqJmsUo53dRngXcWsoEfcFzLQ-J1V5oZOGUL03%40mail.gmail.com

```
Is there an easy command to get a symbolic reference to the upstream
branch of a tracking branch?

For example, to get the current branch name I can do this:

$ git symbolic-ref HEAD
refs/heads/mybranchname

Now I can see the upstream name as follows

$ git branch -vv
branch1 ...
mybranchname sha [upstreamname: ahead n] ...
branch3 ...

My question is is there a way to get upstreamname directly to stdout,
similar to the symbolic-ref command?

(I don't want to have to type it manually; tab completion helps a
little, but looking for more. Plus this would be necessary to avoid
scraping in a script.)

```

## Pat Notz, 2010-09-23 04:05

Subject: Re: get-upstream
Message-ID: <AANLkTikQ8sHrp+sSZ8e8u7L+6=NHVY3cD9DwChAzLEk0@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikQ8sHrp%2BsSZ8e8u7L%2B6%3DNHVY3cD9DwChAzLEk0%40mail.gmail.com
In-Reply-To: <AANLkTikqJmsUo53dRngXcWsoEfcFzLQ-J1V5oZOGUL03@mail.gmail.com>

```
$ git rev-parse --symbolic-full-name @{upstream}

On Wed, Sep 22, 2010 at 9:46 PM, Ramana Kumar <ramana.kumar@gmail.com> wrote:
> Is there an easy command to get a symbolic reference to the upstream
> branch of a tracking branch?
>
> For example, to get the current branch name I can do this:
>
> $ git symbolic-ref HEAD
> refs/heads/mybranchname
>
> Now I can see the upstream name as follows
>
> $ git branch -vv
> branch1 ...
> mybranchname sha [upstreamname: ahead n] ...
> branch3 ...
>
> My question is is there a way to get upstreamname directly to stdout,
> similar to the symbolic-ref command?
>
> (I don't want to have to type it manually; tab completion helps a
> little, but looking for more. Plus this would be necessary to avoid
> scraping in a script.)
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

```

## Pat Notz, 2010-09-23 04:15

Subject: Re: get-upstream
Message-ID: <AANLkTikYnj_00Pdsm+QM1=kvqMpeKDCeOOqOS0XEwMXg@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikYnj_00Pdsm%2BQM1%3DkvqMpeKDCeOOqOS0XEwMXg%40mail.gmail.com
In-Reply-To: <AANLkTikQ8sHrp+sSZ8e8u7L+6=NHVY3cD9DwChAzLEk0@mail.gmail.com>

```
On Wed, Sep 22, 2010 at 10:05 PM, Pat Notz <patnotz@gmail.com> wrote:
> $ git rev-parse --symbolic-full-name @{upstream}

In all fairness, the @{upstream} syntax requires git >= 1.7.0

http://www.kernel.org/pub/software/scm/git/docs/RelNotes-1.7.0.txt

```

## Ramana Kumar, 2010-09-23 04:16

Subject: Re: get-upstream
Message-ID: <AANLkTi=QnP0CUCU=6fR50UzphnVMVvmfe9mkqpf1NHLt@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DQnP0CUCU%3D6fR50UzphnVMVvmfe9mkqpf1NHLt%40mail.gmail.com
In-Reply-To: <AANLkTikYnj_00Pdsm+QM1=kvqMpeKDCeOOqOS0XEwMXg@mail.gmail.com>

```
Thanks Pat - that's awesome.
Is there a git shortcut for removing the refs/remotes or refs/heads
prefix? (I know I can just use other progs for that too)

On Thu, Sep 23, 2010 at 2:15 PM, Pat Notz <patnotz@gmail.com> wrote:
> On Wed, Sep 22, 2010 at 10:05 PM, Pat Notz <patnotz@gmail.com> wrote:
>> $ git rev-parse --symbolic-full-name @{upstream}
>
> In all fairness, the @{upstream} syntax requires git >= 1.7.0
>
> http://www.kernel.org/pub/software/scm/git/docs/RelNotes-1.7.0.txt
>

```

## Jeff King, 2010-09-23 05:36

Subject: Re: get-upstream
Message-ID: <20100923053600.GA27540@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20100923053600.GA27540%40sigill.intra.peff.net
In-Reply-To: <AANLkTikYnj_00Pdsm+QM1=kvqMpeKDCeOOqOS0XEwMXg@mail.gmail.com>

```
On Wed, Sep 22, 2010 at 10:15:00PM -0600, Pat Notz wrote:

> On Wed, Sep 22, 2010 at 10:05 PM, Pat Notz <patnotz@gmail.com> wrote:
> > $ git rev-parse --symbolic-full-name @{upstream}
> 
> In all fairness, the @{upstream} syntax requires git >= 1.7.0

You can also use:

  git for-each-ref --format='%(upstream)' `git symbolic-ref HEAD`

which has worked since v1.6.3. It also has the advantage that you can
ask for the upstream of something besides the HEAD.

-Peff

```

## Jeff King, 2010-09-23 05:37

Subject: Re: get-upstream
Message-ID: <20100923053717.GB27540@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20100923053717.GB27540%40sigill.intra.peff.net
In-Reply-To: <AANLkTi=QnP0CUCU=6fR50UzphnVMVvmfe9mkqpf1NHLt@mail.gmail.com>

```
On Thu, Sep 23, 2010 at 02:16:43PM +1000, Ramana Kumar wrote:

> Thanks Pat - that's awesome.
> Is there a git shortcut for removing the refs/remotes or refs/heads
> prefix? (I know I can just use other progs for that too)

If you use the for-each-ref solution, you can use the :short modifier,
like:

  git for-each-ref --format='%(upstream:short)' `git symbolic-ref HEAD`

-Peff

```

## Pat Notz, 2010-09-23 14:28

Subject: Re: get-upstream
Message-ID: <AANLkTinm2sJbhiZ8pUNtv4KUE3tqWtsDVzKpNXUa=Dn7@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinm2sJbhiZ8pUNtv4KUE3tqWtsDVzKpNXUa%3DDn7%40mail.gmail.com
In-Reply-To: <20100923053717.GB27540@sigill.intra.peff.net>

```
On Wed, Sep 22, 2010 at 11:37 PM, Jeff King <peff@peff.net> wrote:
> On Thu, Sep 23, 2010 at 02:16:43PM +1000, Ramana Kumar wrote:
>
>> Thanks Pat - that's awesome.
>> Is there a git shortcut for removing the refs/remotes or refs/heads
>> prefix? (I know I can just use other progs for that too)
>
> If you use the for-each-ref solution, you can use the :short modifier,
> like:
>
>  git for-each-ref --format='%(upstream:short)' `git symbolic-ref HEAD`
>
> -Peff
>

That's pretty cool.  Using the >=1.7.0 syntax you can also specify an
alternate branch like

$ git rev-parse --symbolic-full-name other-branch@{upstream}

Also, looking at TFM I discovered that @{u} is valid shorthand for
@{upstream} -- sweet.

Still, I think Peff's solution looks best and covers more versions of git.

```
