{"thread":{"id":"18733","subject":"[question] how can i verify whether a local branch is tracking a remote branch?","startedAt":"2009-04-05T10:32:29Z","lastAt":"2009-04-07T07:59:47Z","messageCount":13,"participants":["Paolo Ciarrocchi","Jeff King","Junio C Hamano","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"110404","messageId":"4d8e3fd30904050332w394cccbaq5b82d2a53ed357a3@mail.gmail.com","threadId":"18733","inReplyTo":null,"subject":"[question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Paolo Ciarrocchi","fromEmail":"paolo.ciarrocchi@gmail.com","sentAt":"2009-04-05T10:32:29Z","receivedAt":"2009-04-05T10:32:29Z","isPatch":false,"sender":{"key":"paolo.ciarrocchi@gmail.com","avatar":null},"body":"Hi all,\nis there a way to verify, using the UI, whether a local branch is\ntracking a remote branch?\n\nCiao,\n-- \nPaolo\nhttp://paolo.ciarrocchi.googlepages.com/\nhttp://mypage.vodafone.it/\n"},{"id":"110419","messageId":"20090405144413.GC2076@sigill.intra.peff.net","threadId":"18733","inReplyTo":"4d8e3fd30904050332w394cccbaq5b82d2a53ed357a3@mail.gmail.com","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-05T14:44:13Z","receivedAt":"2009-04-05T14:44:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Apr 05, 2009 at 12:32:29PM +0200, Paolo Ciarrocchi wrote:\n\n> is there a way to verify, using the UI, whether a local branch is\n> tracking a remote branch?\n\nDo you mean \"whether it is tracking any branch\", or \"whether the branch\nis is tracking is remote\"?\n\nIf the former, then I think if one of branch.$branch.{merge,rebase}\nis set, it is tracking something. The tracked thing is remote unless\nbranch.$branch.remote is \".\".\n\n-Peff\n"},{"id":"110462","messageId":"4d8e3fd30904051425w6739a12fp5666e71e8b2d7958@mail.gmail.com","threadId":"18733","inReplyTo":"20090405144413.GC2076@sigill.intra.peff.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Paolo Ciarrocchi","fromEmail":"paolo.ciarrocchi@gmail.com","sentAt":"2009-04-05T21:25:29Z","receivedAt":"2009-04-05T21:25:29Z","isPatch":false,"sender":{"key":"paolo.ciarrocchi@gmail.com","avatar":null},"body":"On 4/5/09, Jeff King <peff@peff.net> wrote:\n> On Sun, Apr 05, 2009 at 12:32:29PM +0200, Paolo Ciarrocchi wrote:\n>\n>> is there a way to verify, using the UI, whether a local branch is\n>> tracking a remote branch?\n>\n> Do you mean \"whether it is tracking any branch\", or \"whether the branch\n> is is tracking is remote\"?\n\nI mean whether it is tracking a branch and if it is I want to know\nwhich branch is being tracked.\n\n> If the former, then I think if one of branch.$branch.{merge,rebase}\n> is set, it is tracking something. The tracked thing is remote unless\n> branch.$branch.remote is \".\".\n\nAn example:\n$ git clone -n URL temp\n$ cd temp\n$ git branch -r\n  origin/master\n  origin/foo\n  Origin/bar\n$ git checkout --track -b foo origin/foo\n\nNow, how can I know that foo is tracking origin/foo ?\n\nThanks.\n\n\nCiao,\n-- \nPaolo\nhttp://paolo.ciarrocchi.googlepages.com/\nhttp://mypage.vodafone.it/\n"},{"id":"110511","messageId":"20090406043426.GC12341@coredump.intra.peff.net","threadId":"18733","inReplyTo":"4d8e3fd30904051425w6739a12fp5666e71e8b2d7958@mail.gmail.com","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-06T04:34:26Z","receivedAt":"2009-04-06T04:34:26Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Apr 05, 2009 at 11:25:29PM +0200, Paolo Ciarrocchi wrote:\n\n> An example:\n> $ git clone -n URL temp\n> $ cd temp\n> $ git branch -r\n>   origin/master\n>   origin/foo\n>   Origin/bar\n> $ git checkout --track -b foo origin/foo\n> \n> Now, how can I know that foo is tracking origin/foo ?\n\nDoing it right is hard. You have to:\n\n  1. check branch.foo.merge and branch.foo.rebase; if no value, it is not\n     tracking anything; if it is, remember that value as $m\n\n  2. check branch.foo.remote for the remote name, $r\n\n  3. check the fetch refspecs for remote $r; these can come from\n     the config, or from .git/remotes/* files. Maybe even .git/branches\n     files; I don't even remember how those work.\n\n  4. find the refspec that fetches from $m; then find the matching\n     destination for that refspec. That is the tracking branch.\n\nE.g., in your example (and using a modern git):\n\n  1. $m is refs/heads/foo\n  2. $r is origin\n  3. The fetch refspec is in remote.origin.fetch, and is generally\n     \"refs/heads/*:refs/remotes/origin/*\"\n  4. So refs/heads/foo becomes refs/remotes/origin/foo.\n     refs/remotes/origin/foo is your tracking branch.\n\nSteps 1 and 2 are easy, but 3 and 4 are a bit nasty. You can fake it by\nassuming that \"refs/heads/$m\" on \"$r\" is always \"refs/remotes/$r/$m\",\nwhich is true for very vanilla setups.\n\nThere is C code that does this, but there is not a good way of accessing\nit from the command-line. The best you can do is \"git remote show\norigin\", which on recent git versions should show something like:\n\n  ...\n  Local branches configured for 'git pull':\n    foo    merges with remote foo\n  ...\n\nBut of course that implies that you already guessed the remote \"origin\".\nAnd it's not using plumbing, so it's not very suitable for scripts.\n\nI don't think it would be unreasonable to expose this functionality via\n\"for-each-ref\". Something like this (which would need cleanup,\ndocumentation, and perhaps a :short variant):\n\n---\ndiff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c\nindex 5cbb4b0..3f418e4 100644\n--- a/builtin-for-each-ref.c\n+++ b/builtin-for-each-ref.c\n@@ -8,6 +8,7 @@\n #include \"blob.h\"\n #include \"quote.h\"\n #include \"parse-options.h\"\n+#include \"remote.h\"\n \n /* Quoting styles */\n #define QUOTE_NONE 0\n@@ -66,6 +67,7 @@ static struct {\n \t{ \"subject\" },\n \t{ \"body\" },\n \t{ \"contents\" },\n+\t{ \"tracking\" },\n };\n \n /*\n@@ -699,6 +701,18 @@ static void populate_value(struct refinfo *ref)\n \t\t\t\tv->s = s;\n \t\t\t}\n \t\t}\n+\t\tif (!strcmp(name, \"tracking\")) {\n+\t\t\tstruct branch *branch;\n+\t\t\tif (prefixcmp(ref->refname, \"refs/heads/\"))\n+\t\t\t\tcontinue;\n+\t\t\tbranch = branch_get(ref->refname + 11);\n+\t\t\tif (branch && branch->merge && branch->merge[0] &&\n+\t\t\t    branch->merge[0]->dst)\n+\t\t\t\tv->s = branch->merge[0]->dst;\n+\t\t\telse\n+\t\t\t\tv->s = NULL;\n+\t\t\tfree(branch); /* XXX should also free other parts? */\n+\t\t}\n \t}\n \n \tgrab_values(ref->value, 0, obj, buf, size);\n\n\n\n\n\n> \n> Thanks.\n> \n> \n> Ciao,\n> -- \n> Paolo\n> http://paolo.ciarrocchi.googlepages.com/\n> http://mypage.vodafone.it/\n"},{"id":"110514","messageId":"7vy6uecpwd.fsf@gitster.siamese.dyndns.org","threadId":"18733","inReplyTo":"20090406043426.GC12341@coredump.intra.peff.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-06T05:28:02Z","receivedAt":"2009-04-06T05:28:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I don't think it would be unreasonable to expose this functionality via\n> \"for-each-ref\". Something like this (which would need cleanup,\n> documentation, and perhaps a :short variant):\n\nI think that is a sane approach, but isn't \"tracking\" a misnomer?  I think\nwhat you are describing is what is called \"the upstream branch\" by the\ndescription of Documentation/config.txt::branch.<name>.merge, and not what\npeople call \"tracking branch\" (see Documentation/glossary-content.txt).\n\nIn a repository with a handcrafted fetch refspec, being able to show\n\"tracking\" information would also be interesting (e.g. a clone of git.git\nmade with pre-1.5.0 git would say \"origin's master\" for refs/heads/origin\nand \"origin's next\" for refs/heads/next), but the separate-remote layout\nis the default these days, so it wouldn't be so interesting anymore.  In\nother words, I am not suggesting you to add \"tracking\" information.\n\nI also wonder if you want to say \"this remote\" and \"that branch\"\nseparately.  As far as I can tell you are not giving the former but only\nthe latter information?\n"},{"id":"110516","messageId":"20090406054920.GA19214@coredump.intra.peff.net","threadId":"18733","inReplyTo":"7vy6uecpwd.fsf@gitster.siamese.dyndns.org","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-06T05:49:20Z","receivedAt":"2009-04-06T05:49:20Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Apr 05, 2009 at 10:28:02PM -0700, Junio C Hamano wrote:\n\n> > I don't think it would be unreasonable to expose this functionality via\n> > \"for-each-ref\". Something like this (which would need cleanup,\n> > documentation, and perhaps a :short variant):\n> \n> I think that is a sane approach, but isn't \"tracking\" a misnomer?  I think\n> what you are describing is what is called \"the upstream branch\" by the\n> description of Documentation/config.txt::branch.<name>.merge, and not what\n> people call \"tracking branch\" (see Documentation/glossary-content.txt).\n\nI think this is the classic \"both of these concepts are called\ntracking and it is confusing\" that people complain about from time to\ntime. This is the value created by \"--track\", and most of the internal\nfunctions call it that (e.g., stat_tracking_info, fill_tracking_info,\netc).\n\nBut I am happy to call it something else if it will reduce confusion.\n\"upstream\" is a fine name, I think (though that is often referring to\nthe upstream _repository_, so maybe somebody might expect it to print\n\"origin\" here).\n\n> I also wonder if you want to say \"this remote\" and \"that branch\"\n> separately.  As far as I can tell you are not giving the former but only\n> the latter information?\n\nWell, I don't think they are two separate parts. \"that branch\" has\nalready used information about the remote to reach its answer, and is\nself-contained. It's all you need to know to do any non-fetching\noperations (like seeing how your commits compare with upstream's, for\nexample).\n\nWhich isn't to say \"this remote\" might not be interesting. But I think\nthat is somewhat independent of this value, and moreover, it is already\ntrivial to find via \"branch.*.remote\" (or are there lookup rules I am\nforgetting about?). The point of this exercise was that it is very\ntricky to do the \"upstream\" correctly, so exposing the C code makes\nsense.\n\n-Peff\n"},{"id":"110529","messageId":"4d8e3fd30904060130l985b0a5x331d215ca6106fd4@mail.gmail.com","threadId":"18733","inReplyTo":"20090406043426.GC12341@coredump.intra.peff.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Paolo Ciarrocchi","fromEmail":"paolo.ciarrocchi@gmail.com","sentAt":"2009-04-06T08:30:21Z","receivedAt":"2009-04-06T08:30:21Z","isPatch":false,"sender":{"key":"paolo.ciarrocchi@gmail.com","avatar":null},"body":"On Mon, Apr 6, 2009 at 6:34 AM, Jeff King <peff@peff.net> wrote:\n> On Sun, Apr 05, 2009 at 11:25:29PM +0200, Paolo Ciarrocchi wrote:\n>\n>> An example:\n>> $ git clone -n URL temp\n>> $ cd temp\n>> $ git branch -r\n>>   origin/master\n>>   origin/foo\n>>   Origin/bar\n>> $ git checkout --track -b foo origin/foo\n>>\n>> Now, how can I know that foo is tracking origin/foo ?\n>\n> Doing it right is hard. You have to:\n>\n>  1. check branch.foo.merge and branch.foo.rebase; if no value, it is not\n>     tracking anything; if it is, remember that value as $m\n>\n>  2. check branch.foo.remote for the remote name, $r\n>\n>  3. check the fetch refspecs for remote $r; these can come from\n>     the config, or from .git/remotes/* files. Maybe even .git/branches\n>     files; I don't even remember how those work.\n>\n>  4. find the refspec that fetches from $m; then find the matching\n>     destination for that refspec. That is the tracking branch.\n>\n> E.g., in your example (and using a modern git):\n>\n>  1. $m is refs/heads/foo\n>  2. $r is origin\n>  3. The fetch refspec is in remote.origin.fetch, and is generally\n>     \"refs/heads/*:refs/remotes/origin/*\"\n>  4. So refs/heads/foo becomes refs/remotes/origin/foo.\n>     refs/remotes/origin/foo is your tracking branch.\n>\n> Steps 1 and 2 are easy, but 3 and 4 are a bit nasty. You can fake it by\n> assuming that \"refs/heads/$m\" on \"$r\" is always \"refs/remotes/$r/$m\",\n> which is true for very vanilla setups.\n>\n> There is C code that does this, but there is not a good way of accessing\n> it from the command-line. The best you can do is \"git remote show\n> origin\", which on recent git versions should show something like:\n>\n>  ...\n>  Local branches configured for 'git pull':\n>    foo    merges with remote foo\n>  ...\n>\n> But of course that implies that you already guessed the remote \"origin\".\n> And it's not using plumbing, so it's not very suitable for scripts.\n>\n> I don't think it would be unreasonable to expose this functionality via\n> \"for-each-ref\". Something like this (which would need cleanup,\n> documentation, and perhaps a :short variant):\n\nJeff,\nthank you very much for your prompt answers and for your patch.\n\nI often act like a GIT \"evangelist\" trying to help friends and\ncolleagues in starting using GIT and one of the \"complaint\" I'm\ngetting is that people expect to get this information out of the\nbranch command.\n\nI mean something like:\n$ git branch\n * foo <-> origin/foo\n\nWhat do you think?\n\nCiao,\n-- \nPaolo\nhttp://paolo.ciarrocchi.googlepages.com/\nhttp://mypage.vodafone.it/\n"},{"id":"110558","messageId":"49D9EEE2.3000607@drmicha.warpmail.net","threadId":"18733","inReplyTo":"20090406043426.GC12341@coredump.intra.peff.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-04-06T12:00:34Z","receivedAt":"2009-04-06T12:00:34Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Jeff King venit, vidit, dixit 06.04.2009 06:34:\n> On Sun, Apr 05, 2009 at 11:25:29PM +0200, Paolo Ciarrocchi wrote:\n> \n>> An example:\n>> $ git clone -n URL temp\n>> $ cd temp\n>> $ git branch -r\n>>   origin/master\n>>   origin/foo\n>>   Origin/bar\n>> $ git checkout --track -b foo origin/foo\n>>\n>> Now, how can I know that foo is tracking origin/foo ?\n> \n> Doing it right is hard. You have to:\n> \n>   1. check branch.foo.merge and branch.foo.rebase; if no value, it is not\n>      tracking anything; if it is, remember that value as $m\n> \n>   2. check branch.foo.remote for the remote name, $r\n> \n>   3. check the fetch refspecs for remote $r; these can come from\n>      the config, or from .git/remotes/* files. Maybe even .git/branches\n>      files; I don't even remember how those work.\n> \n>   4. find the refspec that fetches from $m; then find the matching\n>      destination for that refspec. That is the tracking branch.\n> \n> E.g., in your example (and using a modern git):\n> \n>   1. $m is refs/heads/foo\n>   2. $r is origin\n>   3. The fetch refspec is in remote.origin.fetch, and is generally\n>      \"refs/heads/*:refs/remotes/origin/*\"\n>   4. So refs/heads/foo becomes refs/remotes/origin/foo.\n>      refs/remotes/origin/foo is your tracking branch.\n> \n> Steps 1 and 2 are easy, but 3 and 4 are a bit nasty. You can fake it by\n> assuming that \"refs/heads/$m\" on \"$r\" is always \"refs/remotes/$r/$m\",\n> which is true for very vanilla setups.\n> \n> There is C code that does this, but there is not a good way of accessing\n> it from the command-line. The best you can do is \"git remote show\n> origin\", which on recent git versions should show something like:\n> \n>   ...\n>   Local branches configured for 'git pull':\n>     foo    merges with remote foo\n>   ...\n> \n> But of course that implies that you already guessed the remote \"origin\".\n> And it's not using plumbing, so it's not very suitable for scripts.\n> \n> I don't think it would be unreasonable to expose this functionality via\n> \"for-each-ref\". Something like this (which would need cleanup,\n> documentation, and perhaps a :short variant):\n> \n> ---\n> diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c\n> index 5cbb4b0..3f418e4 100644\n> --- a/builtin-for-each-ref.c\n> +++ b/builtin-for-each-ref.c\n> @@ -8,6 +8,7 @@\n>  #include \"blob.h\"\n>  #include \"quote.h\"\n>  #include \"parse-options.h\"\n> +#include \"remote.h\"\n>  \n>  /* Quoting styles */\n>  #define QUOTE_NONE 0\n> @@ -66,6 +67,7 @@ static struct {\n>  \t{ \"subject\" },\n>  \t{ \"body\" },\n>  \t{ \"contents\" },\n> +\t{ \"tracking\" },\n>  };\n>  \n>  /*\n> @@ -699,6 +701,18 @@ static void populate_value(struct refinfo *ref)\n>  \t\t\t\tv->s = s;\n>  \t\t\t}\n>  \t\t}\n> +\t\tif (!strcmp(name, \"tracking\")) {\n> +\t\t\tstruct branch *branch;\n> +\t\t\tif (prefixcmp(ref->refname, \"refs/heads/\"))\n> +\t\t\t\tcontinue;\n> +\t\t\tbranch = branch_get(ref->refname + 11);\n> +\t\t\tif (branch && branch->merge && branch->merge[0] &&\n> +\t\t\t    branch->merge[0]->dst)\n> +\t\t\t\tv->s = branch->merge[0]->dst;\n\nIsn't that missing out on those cases where you --track (i.e. follow) a\nlocal (upstream) branch? See\n5e6e2b4 (Make local branches behave like remote branches when --tracked,\n2009-04-01)\n\n> +\t\t\telse\n> +\t\t\t\tv->s = NULL;\n> +\t\t\tfree(branch); /* XXX should also free other parts? */\n> +\t\t}\n>  \t}\n>  \n>  \tgrab_values(ref->value, 0, obj, buf, size);\n> \n> \n> \n> \n> \n\nIf we hook it up into git-branch there would be to useful directions:\n\n- \"git branch --follows foo\" could list all branches which follow foo,\nanalogous to --contains. It gives you all your feature work on top of\nfoo, all branches affected by rebasing foo etc.\n\n- \"git branch --whatever foo\" could list the branch whoch foo follows.\n\nI just notices that \"git branch -v foo\" does not give me the \"-v\" output\nfor foo... Improving that would open up the possibility to go for -vv foo.\n\nMichael\n"},{"id":"110632","messageId":"20090406212516.GA882@coredump.intra.peff.net","threadId":"18733","inReplyTo":"4d8e3fd30904060130l985b0a5x331d215ca6106fd4@mail.gmail.com","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-06T21:25:16Z","receivedAt":"2009-04-06T21:25:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Apr 06, 2009 at 10:30:21AM +0200, Paolo Ciarrocchi wrote:\n\n> I often act like a GIT \"evangelist\" trying to help friends and\n> colleagues in starting using GIT and one of the \"complaint\" I'm\n> getting is that people expect to get this information out of the\n> branch command.\n> \n> I mean something like:\n> $ git branch\n>  * foo <-> origin/foo\n> \n> What do you think?\n\nAh. Well, if you just want it for human consumption, that is much\neasier. :) That information is already shown by \"git status\":\n\n  $ git status\n  # On branch next\n  # Your branch is ahead of 'origin/next' by 8 commits.\n  ...\n\n\"git branch -v\" is already looking at the information, but it\nprints only the \"ahead/behind\" summary. E.g.,:\n\n  $ git branch -v\n    bar    1e0672d [behind 5] some commit\n  * baz    dccc1cd [ahead 1, behind 3] other commit\n    foo    787d5a8 [ahead 1] another commit\n    master a0e632e actual upstream master\n\nIt would be pretty trivial to make it do something fancier. The\n(extremely rough) patch below shows the tracking branch when\ndouble-verbosity is given:\n\n  $ git branch -vv\n  * next 2d44318 [origin/next: ahead 9] branch -vv wip\n\nSo the questions are:\n\n  - is this worth it? The verbose information is already available via\n    git status, but only for the current branch.\n\n  - should it be the default with \"-v\", or require \"-vv\"? It take up a\n    bit of screen real estate, which is already in short supply for\n    \"branch -v\"\n\n  - in both the \"status\" and \"branch\" cases, we show nothing if they\n    are equivalent. I guess you would want to see\n\n      * next 2d44318 [origin/next] branch -vv wip\n\n    or\n\n      * next 2d44318 [origin/next: uptodate] branch -vv wip\n\n-Peff\n"},{"id":"110633","messageId":"20090406212935.GB882@coredump.intra.peff.net","threadId":"18733","inReplyTo":"49D9EEE2.3000607@drmicha.warpmail.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-06T21:29:35Z","receivedAt":"2009-04-06T21:29:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Apr 06, 2009 at 02:00:34PM +0200, Michael J Gruber wrote:\n\n> > +\t\tif (!strcmp(name, \"tracking\")) {\n> > +\t\t\tstruct branch *branch;\n> > +\t\t\tif (prefixcmp(ref->refname, \"refs/heads/\"))\n> > +\t\t\t\tcontinue;\n> > +\t\t\tbranch = branch_get(ref->refname + 11);\n> > +\t\t\tif (branch && branch->merge && branch->merge[0] &&\n> > +\t\t\t    branch->merge[0]->dst)\n> > +\t\t\t\tv->s = branch->merge[0]->dst;\n> \n> Isn't that missing out on those cases where you --track (i.e. follow) a\n> local (upstream) branch? See\n> 5e6e2b4 (Make local branches behave like remote branches when --tracked,\n> 2009-04-01)\n\nI thought the logic was in branch_get to handle it. And indeed:\n\n  $ git checkout --track -b new master\n  Branch new set up to track local branch master.\n  Switched to a new branch \"new\"\n  $ git for-each-ref --format='%(refname) %(tracking)'\n  refs/heads/master\n  refs/heads/new refs/heads/master\n\nSo it will point either to something in refs/remotes or in refs/heads,\nas applicable.\n\n> If we hook it up into git-branch there would be to useful directions:\n\nThe difference being that git-branch is porcelain and git-for-each-ref\nis plumbing. So they really serve different purposes.\n\n> - \"git branch --follows foo\" could list all branches which follow foo,\n> analogous to --contains. It gives you all your feature work on top of\n> foo, all branches affected by rebasing foo etc.\n\nSure, that would probably be useful.\n\n> - \"git branch --whatever foo\" could list the branch whoch foo follows.\n> \n> I just notices that \"git branch -v foo\" does not give me the \"-v\" output\n> for foo... Improving that would open up the possibility to go for -vv foo.\n\nSee the \"-vv\" patch I just posted elsewhere in the thread.\n\n-Peff\n"},{"id":"110635","messageId":"4d8e3fd30904061500m7857f0f1i2b76a2113f30c562@mail.gmail.com","threadId":"18733","inReplyTo":"20090406212516.GA882@coredump.intra.peff.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Paolo Ciarrocchi","fromEmail":"paolo.ciarrocchi@gmail.com","sentAt":"2009-04-06T22:00:20Z","receivedAt":"2009-04-06T22:00:20Z","isPatch":false,"sender":{"key":"paolo.ciarrocchi@gmail.com","avatar":null},"body":"On 4/6/09, Jeff King <peff@peff.net> wrote:\n> On Mon, Apr 06, 2009 at 10:30:21AM +0200, Paolo Ciarrocchi wrote:\n\n>> I mean something like:\n>> $ git branch\n>>  * foo <-> origin/foo\n>>\n>> What do you think?\n>\n> Ah. Well, if you just want it for human consumption, that is much\n> easier. :) That information is already shown by \"git status\":\n>\n>   $ git status\n>   # On branch next\n>   # Your branch is ahead of 'origin/next' by 8 commits.\n>   ...\n\nright, but it can only ne used for the current branch.\n\n> \"git branch -v\" is already looking at the information, but it\n> prints only the \"ahead/behind\" summary. E.g.,:\n>\n>   $ git branch -v\n>     bar    1e0672d [behind 5] some commit\n>   * baz    dccc1cd [ahead 1, behind 3] other commit\n>     foo    787d5a8 [ahead 1] another commit\n>     master a0e632e actual upstream master\n>\n> It would be pretty trivial to make it do something fancier. The\n> (extremely rough) patch below shows the tracking branch when\n> double-verbosity is given:\n>\n>   $ git branch -vv\n>   * next 2d44318 [origin/next: ahead 9] branch -vv wip\n\nI like it!\n\n> So the questions are:\n>\n>   - is this worth it? The verbose information is already available via\n>     git status, but only for the current branch.\n\nI think it's a very usefull information.\nI feel like it would be nice to have this information being part of\nthe basic git branch output and not associated to the -vv option.\n\n>   - should it be the default with \"-v\", or require \"-vv\"? It take up a\n>     bit of screen real estate, which is already in short supply for\n>     \"branch -v\"\n\nHow about be just part of the default git branch output?\n\n\n>   - in both the \"status\" and \"branch\" cases, we show nothing if they\n>     are equivalent. I guess you would want to see\n>\n>       * next 2d44318 [origin/next] branch -vv wip\n>\n>     or\n>\n>       * next 2d44318 [origin/next: uptodate] branch -vv wip\n\nSure.\n\nThanks!\n\nCiao,\n-- \nPaolo\nhttp://paolo.ciarrocchi.googlepages.com/\nhttp://mypage.vodafone.it/\n"},{"id":"110654","messageId":"20090407044113.GA26556@coredump.intra.peff.net","threadId":"18733","inReplyTo":"4d8e3fd30904061500m7857f0f1i2b76a2113f30c562@mail.gmail.com","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-04-07T04:41:14Z","receivedAt":"2009-04-07T04:41:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Apr 07, 2009 at 12:00:20AM +0200, Paolo Ciarrocchi wrote:\n\n> > So the questions are:\n> >\n> >   - is this worth it? The verbose information is already available via\n> >     git status, but only for the current branch.\n> \n> I think it's a very usefull information.\n> I feel like it would be nice to have this information being part of\n> the basic git branch output and not associated to the -vv option.\n\nI'm not sure we should disrupt the simplicity of the current \"git\nbranch\" output. I would be curious to hear what others think.\n\n-Peff\n"},{"id":"110675","messageId":"49DB07F3.4000704@drmicha.warpmail.net","threadId":"18733","inReplyTo":"20090406212935.GB882@coredump.intra.peff.net","subject":"Re: [question] how can i verify whether a local branch is tracking a remote branch?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-04-07T07:59:47Z","receivedAt":"2009-04-07T07:59:47Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Jeff King venit, vidit, dixit 06.04.2009 23:29:\n> On Mon, Apr 06, 2009 at 02:00:34PM +0200, Michael J Gruber wrote:\n> \n>>> +\t\tif (!strcmp(name, \"tracking\")) {\n>>> +\t\t\tstruct branch *branch;\n>>> +\t\t\tif (prefixcmp(ref->refname, \"refs/heads/\"))\n>>> +\t\t\t\tcontinue;\n>>> +\t\t\tbranch = branch_get(ref->refname + 11);\n>>> +\t\t\tif (branch && branch->merge && branch->merge[0] &&\n>>> +\t\t\t    branch->merge[0]->dst)\n>>> +\t\t\t\tv->s = branch->merge[0]->dst;\n>>\n>> Isn't that missing out on those cases where you --track (i.e. follow) a\n>> local (upstream) branch? See\n>> 5e6e2b4 (Make local branches behave like remote branches when --tracked,\n>> 2009-04-01)\n> \n> I thought the logic was in branch_get to handle it. And indeed:\n> \n>   $ git checkout --track -b new master\n>   Branch new set up to track local branch master.\n>   Switched to a new branch \"new\"\n>   $ git for-each-ref --format='%(refname) %(tracking)'\n>   refs/heads/master\n>   refs/heads/new refs/heads/master\n> \n> So it will point either to something in refs/remotes or in refs/heads,\n> as applicable.\n\nUhm, yes, sorry for the noise. It was actually me who fixed branch_get()...\n\n> \n>> If we hook it up into git-branch there would be to useful directions:\n> \n> The difference being that git-branch is porcelain and git-for-each-ref\n> is plumbing. So they really serve different purposes.\n> \n>> - \"git branch --follows foo\" could list all branches which follow foo,\n>> analogous to --contains. It gives you all your feature work on top of\n>> foo, all branches affected by rebasing foo etc.\n> \n> Sure, that would probably be useful.\n> \n>> - \"git branch --whatever foo\" could list the branch whoch foo follows.\n>>\n>> I just notices that \"git branch -v foo\" does not give me the \"-v\" output\n>> for foo... Improving that would open up the possibility to go for -vv foo.\n> \n> See the \"-vv\" patch I just posted elsewhere in the thread.\n\nI'll comment there ;)\n\nMichael\n"}]}