git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] show tracking branches with their associated branch names

From
SMSanthosh Kumar Mani <santhoshmani@gmail.com>
Date
Dec 10, 2011, 07:40 UTC
Message-ID
<1323502829.1698.6.camel@sdesktop>

The "git branch" command, by default, displays the local branches. There is no visual distinction made between the tracking branches and normal local branches. This patch enables the "git branch" to display tracking info for tracking branches:

Before this patch:
  $ git branch
  * master
    local
After this patch:
  $ git branch
  * master [origin/master]
    local
Signed-off-by: Santhosh Kumar Mani <santhoshmani@gmail.com>
---
 builtin/branch.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index e1e486e..4841416 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -373,6 +373,19 @@ static int ref_cmp(const void *r1, const void *r2)
 	return strcmp(c1->name, c2->name);
 }
 
+static int get_tracking_branch_name(struct strbuf *name, const char
*branch_name)
+{
+	struct branch *branch = branch_get(branch_name);
+
+	if (branch && branch->merge && branch->merge[0]->dst) {
+		strbuf_addf(name, " [%s]",
+				shorten_unambiguous_ref(branch->merge[0]->dst, 0));
+		return 1;
+	}
+
+	return 0;
+}
+
 static void fill_tracking_info(struct strbuf *stat, const char
*branch_name,
 		int show_upstream_ref)
 {
@@ -475,6 +488,9 @@ static void print_ref_item(struct ref_item *item,
int maxwidth, int verbose,
 	else if (verbose)
 		/* " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" */
 		add_verbose_info(&out, item, verbose, abbrev);
+	else if (get_tracking_branch_name(&out, item->name))
+		;
+
 	printf("%s\n", out.buf);
 	strbuf_release(&name);
 	strbuf_release(&out);
-- 
1.7.0.4
Next: Vincent van Ravesteijn
Message 1 of 5 in “show tracking branches with their associated branch names”
  1. show tracking branches with their associated branch namesSanthosh Kumar Mani, Dec 10, 2011
  2. Vincent van RavesteijnDec 10, 2011
  3. Santhosh Kumar ManiDec 10, 2011
  4. Junio C HamanoDec 12, 2011
  5. SanthoshDec 12, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.