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

[PATCH 1/2] Teach clone to clone just one remote branch using --track

From
David Soria Parra <sn_@gmx.net>
Date
Nov 30, 2009, 13:16 UTC
Message-ID
<1259587004-14633-2-git-send-email-sn_@gmx.net>
In-Reply-To
<1259587004-14633-1-git-send-email-sn_@gmx.net>
From: David Soria Parra <dsp@php.net>

Add a --track option that can be used to clone just the given branch from the remote and nothing else. This is done by setting the remote.<branch>.fetch option before cloning. This option cannot be used together with --mirror. For example using

    git clone --track next git://git.kernel.org/pub/scm/git/git.git
will just clone the next branch from the git.git repository.

The option is called --track to ensure clean wording with 'git remote add --track'.

Signed-off-by: David Soria Parra <dsp@php.net>
---
 builtin-clone.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index 5df8b0f..bc335ee 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -43,6 +43,7 @@ static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
 static char *option_upload_pack = "git-upload-pack";
+static char *option_track = NULL;
 static int option_verbose;
 
 static struct option builtin_clone_options[] = {
@@ -76,6 +77,8 @@ static struct option builtin_clone_options[] = {
 		   "path to git-upload-pack on the remote"),
 	OPT_STRING(0, "depth", &option_depth, "depth",
 		    "create a shallow clone of that depth"),
+	OPT_STRING('t', "track", &option_track, "branch",
+			"remote branche to track"),
 
 	OPT_END()
 };
@@ -483,7 +486,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
 
-	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
+	if (option_track) {
+		if (option_mirror)
+			return error("Cannot use --track together with --mirror");
+		strbuf_addf(&value, "+%s%s:%s%s", src_ref_prefix, option_track, branch_top.buf, option_track);
+		option_branch = option_track;
+	} else {
+		strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
+	}
 
 	if (option_mirror || !option_bare) {
 		/* Configure the remote */
-- 
1.6.6.rc0.268.g1c272
Previous: David Soria ParraNext: David Soria Parra
Message 2 of 4 in “Add --track option to git clone”
  1. Add --track option to git cloneDavid Soria Parra, Nov 30, 2009
  2. 1/2 Teach clone to clone just one remote branch using --trackDavid Soria Parra, Nov 30, 2009
  3. 2/2 Documentation: Add --track option to the git clone manpageDavid Soria Parra, Nov 30, 2009
  4. Michael J GruberNov 30, 2009

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.