git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [question] how can i verify whether a local branch is tracking a  remote branch?
Date: Mon, 6 Apr 2009 10:30:21 +0200	[thread overview]
Message-ID: <4d8e3fd30904060130l985b0a5x331d215ca6106fd4@mail.gmail.com> (raw)
In-Reply-To: <20090406043426.GC12341@coredump.intra.peff.net>

On Mon, Apr 6, 2009 at 6:34 AM, Jeff King <peff@peff.net> wrote:
> On Sun, Apr 05, 2009 at 11:25:29PM +0200, Paolo Ciarrocchi wrote:
>
>> An example:
>> $ git clone -n URL temp
>> $ cd temp
>> $ git branch -r
>>   origin/master
>>   origin/foo
>>   Origin/bar
>> $ git checkout --track -b foo origin/foo
>>
>> Now, how can I know that foo is tracking origin/foo ?
>
> Doing it right is hard. You have to:
>
>  1. check branch.foo.merge and branch.foo.rebase; if no value, it is not
>     tracking anything; if it is, remember that value as $m
>
>  2. check branch.foo.remote for the remote name, $r
>
>  3. check the fetch refspecs for remote $r; these can come from
>     the config, or from .git/remotes/* files. Maybe even .git/branches
>     files; I don't even remember how those work.
>
>  4. find the refspec that fetches from $m; then find the matching
>     destination for that refspec. That is the tracking branch.
>
> E.g., in your example (and using a modern git):
>
>  1. $m is refs/heads/foo
>  2. $r is origin
>  3. The fetch refspec is in remote.origin.fetch, and is generally
>     "refs/heads/*:refs/remotes/origin/*"
>  4. So refs/heads/foo becomes refs/remotes/origin/foo.
>     refs/remotes/origin/foo is your tracking branch.
>
> Steps 1 and 2 are easy, but 3 and 4 are a bit nasty. You can fake it by
> assuming that "refs/heads/$m" on "$r" is always "refs/remotes/$r/$m",
> which is true for very vanilla setups.
>
> There is C code that does this, but there is not a good way of accessing
> it from the command-line. The best you can do is "git remote show
> origin", which on recent git versions should show something like:
>
>  ...
>  Local branches configured for 'git pull':
>    foo    merges with remote foo
>  ...
>
> But of course that implies that you already guessed the remote "origin".
> And it's not using plumbing, so it's not very suitable for scripts.
>
> I don't think it would be unreasonable to expose this functionality via
> "for-each-ref". Something like this (which would need cleanup,
> documentation, and perhaps a :short variant):

Jeff,
thank you very much for your prompt answers and for your patch.

I often act like a GIT "evangelist" trying to help friends and
colleagues in starting using GIT and one of the "complaint" I'm
getting is that people expect to get this information out of the
branch command.

I mean something like:
$ git branch
 * foo <-> origin/foo

What do you think?

Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/

  parent reply	other threads:[~2009-04-06  8:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-05 10:32 [question] how can i verify whether a local branch is tracking a remote branch? Paolo Ciarrocchi
2009-04-05 14:44 ` Jeff King
2009-04-05 21:25   ` Paolo Ciarrocchi
2009-04-06  4:34     ` Jeff King
2009-04-06  5:28       ` Junio C Hamano
2009-04-06  5:49         ` Jeff King
2009-04-06  8:30       ` Paolo Ciarrocchi [this message]
2009-04-06 21:25         ` Jeff King
2009-04-06 22:00           ` Paolo Ciarrocchi
2009-04-07  4:41             ` Jeff King
2009-04-06 12:00       ` Michael J Gruber
2009-04-06 21:29         ` Jeff King
2009-04-07  7:59           ` Michael J Gruber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d8e3fd30904060130l985b0a5x331d215ca6106fd4@mail.gmail.com \
    --to=paolo.ciarrocchi@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).