{"thread":{"id":"25203","subject":"get-upstream","startedAt":"2010-09-23T03:46:06Z","lastAt":"2010-09-23T14:28:21Z","messageCount":7,"participants":["Ramana Kumar","Pat Notz","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"151335","messageId":"AANLkTikqJmsUo53dRngXcWsoEfcFzLQ-J1V5oZOGUL03@mail.gmail.com","threadId":"25203","inReplyTo":null,"subject":"get-upstream","fromName":"Ramana Kumar","fromEmail":"ramana.kumar@gmail.com","sentAt":"2010-09-23T03:46:06Z","receivedAt":"2010-09-23T03:46:06Z","isPatch":false,"sender":{"key":"ramana.kumar@gmail.com","avatar":"https://gravatar.com/avatar/c1e354b4b3844c33709698d3c6491eb791f04384343001b78b4816b6ba3fa8a9?d=mp&s=160"},"body":"Is there an easy command to get a symbolic reference to the upstream\nbranch of a tracking branch?\n\nFor example, to get the current branch name I can do this:\n\n$ git symbolic-ref HEAD\nrefs/heads/mybranchname\n\nNow I can see the upstream name as follows\n\n$ git branch -vv\nbranch1 ...\nmybranchname sha [upstreamname: ahead n] ...\nbranch3 ...\n\nMy question is is there a way to get upstreamname directly to stdout,\nsimilar to the symbolic-ref command?\n\n(I don't want to have to type it manually; tab completion helps a\nlittle, but looking for more. Plus this would be necessary to avoid\nscraping in a script.)\n"},{"id":"151336","messageId":"AANLkTikQ8sHrp+sSZ8e8u7L+6=NHVY3cD9DwChAzLEk0@mail.gmail.com","threadId":"25203","inReplyTo":"AANLkTikqJmsUo53dRngXcWsoEfcFzLQ-J1V5oZOGUL03@mail.gmail.com","subject":"Re: get-upstream","fromName":"Pat Notz","fromEmail":"patnotz@gmail.com","sentAt":"2010-09-23T04:05:42Z","receivedAt":"2010-09-23T04:05:42Z","isPatch":false,"sender":{"key":"patnotz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45364?v=4"},"body":"$ git rev-parse --symbolic-full-name @{upstream}\n\nOn Wed, Sep 22, 2010 at 9:46 PM, Ramana Kumar <ramana.kumar@gmail.com> wrote:\n> Is there an easy command to get a symbolic reference to the upstream\n> branch of a tracking branch?\n>\n> For example, to get the current branch name I can do this:\n>\n> $ git symbolic-ref HEAD\n> refs/heads/mybranchname\n>\n> Now I can see the upstream name as follows\n>\n> $ git branch -vv\n> branch1 ...\n> mybranchname sha [upstreamname: ahead n] ...\n> branch3 ...\n>\n> My question is is there a way to get upstreamname directly to stdout,\n> similar to the symbolic-ref command?\n>\n> (I don't want to have to type it manually; tab completion helps a\n> little, but looking for more. Plus this would be necessary to avoid\n> scraping in a script.)\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>\n"},{"id":"151337","messageId":"AANLkTikYnj_00Pdsm+QM1=kvqMpeKDCeOOqOS0XEwMXg@mail.gmail.com","threadId":"25203","inReplyTo":"AANLkTikQ8sHrp+sSZ8e8u7L+6=NHVY3cD9DwChAzLEk0@mail.gmail.com","subject":"Re: get-upstream","fromName":"Pat Notz","fromEmail":"patnotz@gmail.com","sentAt":"2010-09-23T04:15:00Z","receivedAt":"2010-09-23T04:15:00Z","isPatch":false,"sender":{"key":"patnotz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45364?v=4"},"body":"On Wed, Sep 22, 2010 at 10:05 PM, Pat Notz <patnotz@gmail.com> wrote:\n> $ git rev-parse --symbolic-full-name @{upstream}\n\nIn all fairness, the @{upstream} syntax requires git >= 1.7.0\n\nhttp://www.kernel.org/pub/software/scm/git/docs/RelNotes-1.7.0.txt\n"},{"id":"151338","messageId":"AANLkTi=QnP0CUCU=6fR50UzphnVMVvmfe9mkqpf1NHLt@mail.gmail.com","threadId":"25203","inReplyTo":"AANLkTikYnj_00Pdsm+QM1=kvqMpeKDCeOOqOS0XEwMXg@mail.gmail.com","subject":"Re: get-upstream","fromName":"Ramana Kumar","fromEmail":"ramana.kumar@gmail.com","sentAt":"2010-09-23T04:16:43Z","receivedAt":"2010-09-23T04:16:43Z","isPatch":false,"sender":{"key":"ramana.kumar@gmail.com","avatar":"https://gravatar.com/avatar/c1e354b4b3844c33709698d3c6491eb791f04384343001b78b4816b6ba3fa8a9?d=mp&s=160"},"body":"Thanks Pat - that's awesome.\nIs there a git shortcut for removing the refs/remotes or refs/heads\nprefix? (I know I can just use other progs for that too)\n\nOn Thu, Sep 23, 2010 at 2:15 PM, Pat Notz <patnotz@gmail.com> wrote:\n> On Wed, Sep 22, 2010 at 10:05 PM, Pat Notz <patnotz@gmail.com> wrote:\n>> $ git rev-parse --symbolic-full-name @{upstream}\n>\n> In all fairness, the @{upstream} syntax requires git >= 1.7.0\n>\n> http://www.kernel.org/pub/software/scm/git/docs/RelNotes-1.7.0.txt\n>\n"},{"id":"151341","messageId":"20100923053600.GA27540@sigill.intra.peff.net","threadId":"25203","inReplyTo":"AANLkTikYnj_00Pdsm+QM1=kvqMpeKDCeOOqOS0XEwMXg@mail.gmail.com","subject":"Re: get-upstream","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-09-23T05:36:00Z","receivedAt":"2010-09-23T05:36:00Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 22, 2010 at 10:15:00PM -0600, Pat Notz wrote:\n\n> On Wed, Sep 22, 2010 at 10:05 PM, Pat Notz <patnotz@gmail.com> wrote:\n> > $ git rev-parse --symbolic-full-name @{upstream}\n> \n> In all fairness, the @{upstream} syntax requires git >= 1.7.0\n\nYou can also use:\n\n  git for-each-ref --format='%(upstream)' `git symbolic-ref HEAD`\n\nwhich has worked since v1.6.3. It also has the advantage that you can\nask for the upstream of something besides the HEAD.\n\n-Peff\n"},{"id":"151342","messageId":"20100923053717.GB27540@sigill.intra.peff.net","threadId":"25203","inReplyTo":"AANLkTi=QnP0CUCU=6fR50UzphnVMVvmfe9mkqpf1NHLt@mail.gmail.com","subject":"Re: get-upstream","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-09-23T05:37:17Z","receivedAt":"2010-09-23T05:37:17Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Sep 23, 2010 at 02:16:43PM +1000, Ramana Kumar wrote:\n\n> Thanks Pat - that's awesome.\n> Is there a git shortcut for removing the refs/remotes or refs/heads\n> prefix? (I know I can just use other progs for that too)\n\nIf you use the for-each-ref solution, you can use the :short modifier,\nlike:\n\n  git for-each-ref --format='%(upstream:short)' `git symbolic-ref HEAD`\n\n-Peff\n"},{"id":"151360","messageId":"AANLkTinm2sJbhiZ8pUNtv4KUE3tqWtsDVzKpNXUa=Dn7@mail.gmail.com","threadId":"25203","inReplyTo":"20100923053717.GB27540@sigill.intra.peff.net","subject":"Re: get-upstream","fromName":"Pat Notz","fromEmail":"patnotz@gmail.com","sentAt":"2010-09-23T14:28:21Z","receivedAt":"2010-09-23T14:28:21Z","isPatch":false,"sender":{"key":"patnotz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45364?v=4"},"body":"On Wed, Sep 22, 2010 at 11:37 PM, Jeff King <peff@peff.net> wrote:\n> On Thu, Sep 23, 2010 at 02:16:43PM +1000, Ramana Kumar wrote:\n>\n>> Thanks Pat - that's awesome.\n>> Is there a git shortcut for removing the refs/remotes or refs/heads\n>> prefix? (I know I can just use other progs for that too)\n>\n> If you use the for-each-ref solution, you can use the :short modifier,\n> like:\n>\n>  git for-each-ref --format='%(upstream:short)' `git symbolic-ref HEAD`\n>\n> -Peff\n>\n\nThat's pretty cool.  Using the >=1.7.0 syntax you can also specify an\nalternate branch like\n\n$ git rev-parse --symbolic-full-name other-branch@{upstream}\n\nAlso, looking at TFM I discovered that @{u} is valid shorthand for\n@{upstream} -- sweet.\n\nStill, I think Peff's solution looks best and covers more versions of git.\n"}]}