git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* get-upstream
@ 2010-09-23  3:46 Ramana Kumar
  2010-09-23  4:05 ` get-upstream Pat Notz
  0 siblings, 1 reply; 7+ messages in thread
From: Ramana Kumar @ 2010-09-23  3:46 UTC (permalink / raw)
  To: git

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.)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: get-upstream
  2010-09-23  3:46 get-upstream Ramana Kumar
@ 2010-09-23  4:05 ` Pat Notz
  2010-09-23  4:15   ` get-upstream Pat Notz
  0 siblings, 1 reply; 7+ messages in thread
From: Pat Notz @ 2010-09-23  4:05 UTC (permalink / raw)
  To: Ramana Kumar; +Cc: git

$ 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
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: get-upstream
  2010-09-23  4:05 ` get-upstream Pat Notz
@ 2010-09-23  4:15   ` Pat Notz
  2010-09-23  4:16     ` get-upstream Ramana Kumar
  2010-09-23  5:36     ` get-upstream Jeff King
  0 siblings, 2 replies; 7+ messages in thread
From: Pat Notz @ 2010-09-23  4:15 UTC (permalink / raw)
  To: Ramana Kumar; +Cc: git

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: get-upstream
  2010-09-23  4:15   ` get-upstream Pat Notz
@ 2010-09-23  4:16     ` Ramana Kumar
  2010-09-23  5:37       ` get-upstream Jeff King
  2010-09-23  5:36     ` get-upstream Jeff King
  1 sibling, 1 reply; 7+ messages in thread
From: Ramana Kumar @ 2010-09-23  4:16 UTC (permalink / raw)
  To: Pat Notz; +Cc: git

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
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: get-upstream
  2010-09-23  4:15   ` get-upstream Pat Notz
  2010-09-23  4:16     ` get-upstream Ramana Kumar
@ 2010-09-23  5:36     ` Jeff King
  1 sibling, 0 replies; 7+ messages in thread
From: Jeff King @ 2010-09-23  5:36 UTC (permalink / raw)
  To: Pat Notz; +Cc: Ramana Kumar, git

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: get-upstream
  2010-09-23  4:16     ` get-upstream Ramana Kumar
@ 2010-09-23  5:37       ` Jeff King
  2010-09-23 14:28         ` get-upstream Pat Notz
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2010-09-23  5:37 UTC (permalink / raw)
  To: Ramana Kumar; +Cc: Pat Notz, git

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: get-upstream
  2010-09-23  5:37       ` get-upstream Jeff King
@ 2010-09-23 14:28         ` Pat Notz
  0 siblings, 0 replies; 7+ messages in thread
From: Pat Notz @ 2010-09-23 14:28 UTC (permalink / raw)
  To: Jeff King; +Cc: Ramana Kumar, git

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-09-23 14:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-23  3:46 get-upstream Ramana Kumar
2010-09-23  4:05 ` get-upstream Pat Notz
2010-09-23  4:15   ` get-upstream Pat Notz
2010-09-23  4:16     ` get-upstream Ramana Kumar
2010-09-23  5:37       ` get-upstream Jeff King
2010-09-23 14:28         ` get-upstream Pat Notz
2010-09-23  5:36     ` get-upstream Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).