threads / patch / 18097

patchgit-clone: Add option --branch to override initial branch

Subject: [PATCH] git-clone: Add option --branch to override initial branch

## tl;dr

19 messages between Mar 2, 2009 and Mar 12, 2009. Diffs are folded; open one to read it.

replies: 18people: 6as markdown or json

Tor Arne Vestbø· Mar 2, 2009, 22:11 UTC · lore

The options --branch and -b allow the user to override the initial branch created and checked out by git-clone. Normally this is the active branch of the remote repository, which is also the fallback if the selected branch is not found.

Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---
 Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |   33 +++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)
Show changes to 2 files +34 −4

Documentation/git-clone.txt, builtin-clone.c

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 95f08b9..e7feb4d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -119,6 +119,11 @@ then the cloned repository will become corrupt.
 	Instead of using the remote name 'origin' to keep track
 	of the upstream repository, use <name> instead.
 
+--branch <name>::
+-b <name>::
+	Instead of using the remote repository's active branch as the
+	initial branch, use <name> instead.
+
 --upload-pack <upload-pack>::
 -u <upload-pack>::
 	When given, and the repository to clone from is accessed
diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..601c2c2 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,6 +38,7 @@ static int option_quiet, option_no_checkout, option_bare, option_mirror;
 static int option_local, option_no_hardlinks, option_shared;
 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 int option_verbose;
 
@@ -66,6 +67,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('b', "branch", &option_branch, "branch",
+		    "initial remote branch to check out"),
 
 	OPT_END()
 };
@@ -372,7 +375,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
 	int dest_exists;
-	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
+	const struct ref *refs, *mapped_refs;
+	const struct ref *remote_head = NULL;
+	const struct ref *head_points_at = NULL;
 	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
@@ -545,12 +550,32 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 		mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
 
-		head_points_at = locate_head(refs, mapped_refs, &remote_head);
+		if (option_branch) {
+		    const int offset = 11;
+		    const char *branch = option_branch;
+		    if (!prefixcmp(branch, "refs/heads/"))
+			branch += offset;
+
+		    const struct ref *r;
+		    for (r = mapped_refs; r; r = r->next) {
+			if (!strcmp(r->name + offset, branch)) {
+			    /* Override initial branch */
+			    head_points_at = r;
+			    remote_head = r;
+			    break;
+			}
+		    }
+
+		    if (!head_points_at)
+			warning("remote has no branch named '%s', "
+				"falling back to default.", option_branch);
+		}
+
+		if (!head_points_at)
+		    head_points_at = locate_head(refs, mapped_refs, &remote_head);
 	}
 	else {
 		warning("You appear to have cloned an empty repository.");
-		head_points_at = NULL;
-		remote_head = NULL;
 		option_no_checkout = 1;
 		if (!option_bare)
 			install_branch_config("master", option_origin,
-- 
1.6.2.rc2.16.gf474c.dirty
Johannes Schindelin· Mar 2, 2009, 23:48 UTC · re: Tor Arne Vestbø · lore

Re: [PATCH] git-clone: Add option --branch to override initial branch

Hi,
On Mon, 2 Mar 2009, Tor Arne Vestbø wrote:
> The options --branch and -b allow the user to override the initial 
> branch created and checked out by git-clone. Normally this is the active 
> branch of the remote repository, which is also the fallback if the 
> selected branch is not found.

I do not think that falling back if the selected branch is not found is a wise choice.

Besides, the common way to check out something different than the remote's HEAD is like this:

	$ git clone -n $URL
	$ cd $DIR
	$ git checkout -t origin/$BRANCH
I am undecided if that is good enough, or your patch is needed.

Ciao, Dscho

Junio C Hamano· Mar 3, 2009, 00:09 UTC · re: Johannes Schindelin · lore

Re: [PATCH] git-clone: Add option --branch to override initial branch

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 20 quoted lines
> Hi,
>
> On Mon, 2 Mar 2009, Tor Arne Vestbø wrote:
>
>> The options --branch and -b allow the user to override the initial 
>> branch created and checked out by git-clone. Normally this is the active 
>> branch of the remote repository, which is also the fallback if the 
>> selected branch is not found.
>
> I do not think that falling back if the selected branch is not found is a 
> wise choice.
>
> Besides, the common way to check out something different than the remote's 
> HEAD is like this:
>
> 	$ git clone -n $URL
> 	$ cd $DIR
> 	$ git checkout -t origin/$BRANCH
>
> I am undecided if that is good enough, or your patch is needed.
I am fairly negative on this one, if it matters.
Tor Arne Vestbø· Mar 3, 2009, 00:11 UTC · re: Johannes Schindelin · lore

Re: [PATCH] git-clone: Add option --branch to override initial branch

Johannes Schindelin wrote:
Show 8 quoted lines
> On Mon, 2 Mar 2009, Tor Arne Vestbø wrote:
>> The options --branch and -b allow the user to override the initial 
>> branch created and checked out by git-clone. Normally this is the active 
>> branch of the remote repository, which is also the fallback if the 
>> selected branch is not found.
> 
> I do not think that falling back if the selected branch is not found is a 
> wise choice.

Ah, was not sure what the proper response would be. I'll resubmit with a die() instead.

Show 6 quoted lines
> Besides, the common way to check out something different than the remote's 
> HEAD is like this:
> 
> 	$ git clone -n $URL
> 	$ cd $DIR
> 	$ git checkout -t origin/$BRANCH
Yepp, plus removing the original branch:
 $ git branch -D $ORIGINAL_ACTIVE_BRANCH # typically master
> I am undecided if that is good enough, or your patch is needed.

The idea was to be able to tell someone "hey, if you want to hack on some feature for next, do the following:"

 $ git clone git://git.kernel.org/pub/scm/git/git.git -b next

Maybe next is not such a good example, since it does not diverge that much from master and pu, but imagine a repository with a master, plus other branches that over time diverge from master (where you would typically use git-new-workdir to have them in a separate working tree).

In that situation it would be nice to be able to tell someone, hey, if you want to work on this odd branch which is not master, just do -b.

Tor Arne
Tor Arne Vestbø· Mar 3, 2009, 00:33 UTC · re: Johannes Schindelin · lore

[PATCH v2] git-clone: Add option --branch to override initial branch

The options --branch and -b allow the user to override the initial branch created and checked out by git-clone (normally this is the active branch of the remote repository).

If the selected branch is not found the operation aborts.
Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---
Something like this?
Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |   32 ++++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
Show changes to 2 files +33 −4

Documentation/git-clone.txt, builtin-clone.c

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 95f08b9..e7feb4d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -119,6 +119,11 @@ then the cloned repository will become corrupt.
 	Instead of using the remote name 'origin' to keep track
 	of the upstream repository, use <name> instead.
 
+--branch <name>::
+-b <name>::
+	Instead of using the remote repository's active branch as the
+	initial branch, use <name> instead.
+
 --upload-pack <upload-pack>::
 -u <upload-pack>::
 	When given, and the repository to clone from is accessed
diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..5fc01ce 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,6 +38,7 @@ static int option_quiet, option_no_checkout, option_bare, option_mirror;
 static int option_local, option_no_hardlinks, option_shared;
 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 int option_verbose;
 
@@ -66,6 +67,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('b', "branch", &option_branch, "branch",
+		    "initial remote branch to check out"),
 
 	OPT_END()
 };
@@ -372,7 +375,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
 	int dest_exists;
-	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
+	const struct ref *refs, *mapped_refs;
+	const struct ref *remote_head = NULL;
+	const struct ref *head_points_at = NULL;
 	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
@@ -545,12 +550,31 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 		mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
 
-		head_points_at = locate_head(refs, mapped_refs, &remote_head);
+		if (option_branch) {
+		    const int offset = 11;
+		    const char *branch = option_branch;
+		    if (!prefixcmp(branch, "refs/heads/"))
+			branch += offset;
+
+		    const struct ref *r;
+		    for (r = mapped_refs; r; r = r->next) {
+			if (!strcmp(r->name + offset, branch)) {
+			    /* Override initial branch */
+			    head_points_at = r;
+			    remote_head = r;
+			    break;
+			}
+		    }
+
+		    if (!head_points_at)
+			die("remote has no branch named '%s'.", option_branch);
+
+		} else {
+		    head_points_at = locate_head(refs, mapped_refs, &remote_head);
+		}
 	}
 	else {
 		warning("You appear to have cloned an empty repository.");
-		head_points_at = NULL;
-		remote_head = NULL;
 		option_no_checkout = 1;
 		if (!option_bare)
 			install_branch_config("master", option_origin,
-- 
1.6.2.rc2.17.g2aa38
Johannes Schindelin· Mar 3, 2009, 09:07 UTC · re: Tor Arne Vestbø · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Hi,
On Tue, 3 Mar 2009, Tor Arne Vestbø wrote:
> Something like this?

Leaving unnecessary initialization and funny indentation aside for a moment, what about the objection that it might not be necessary?

Keep in mind: your change (as every change) bears the potential to introduce bugs and to complicate the user interface. The change must be worth those risks.

So could you make a case (if you resubmit a patch, in the commit message, please) why your change is desirable?

Thanks, Dscho

Tor Arne Vestbø· Mar 3, 2009, 16:47 UTC · re: Johannes Schindelin · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Johannes Schindelin wrote:
> Leaving unnecessary initialization and funny indentation aside for a 
> moment,

I do appreciate the feedback though. C is not my primary language, and I'm happy to learn from my mistakes :-)

> Keep in mind: your change (as every change) bears the potential to 
> introduce bugs and to complicate the user interface.  The change must be 
> worth those risks.
I fully understand. Here is my rationale for why it's worth the risk:

Imagine you have a project called Foo, which has active development on the 'master' branch, and not quite so active development on the more stable version branch '1.6' (which v1.6.0 and v1.6.1 was tagged from).

Now, you want to put up info on the project web page / wiki on how to contribute to project Foo. This information is for new contributors -- who may be unfamiliar with git and it's inner workings. You write:

"To get started contributing to project Foo, please clone using:
   $ git clone git://git.foo.com/project.git
"
This looks nice and inviting.

You also want to provide instructions for those who would like to contribute to the more stable branch of project Foo, 1.6:

"If you would like to contribute to the stable 1.6 branch, do:
   $ git clone -n git://git.foo.com/project.git
   $ cd project
   $ git checkout -t origin/1.6
   $ git branch -D master
"
Which is not so nice and inviting. At least not compared to:
"If you would like to contribute to the stable 1.6 branch, do:
   $ git clone git://git.foo.com/project.git --branch 1.6
"

Remember these are new contributors, unfamiliar with git. Presenting them with a list of four commands that have to be run to get started (commands which incidentally also are the first-ones new users mix up), is not ideal. "What does -n do?", "What does -t do?", "What's a tracking branch?", "Origin? What's that?", "What does -D do?", "Delete?! Will I delete the main development line!?", etc.. :)

Also, remember that these commands are not something that can be scripted or put into an alias, because these users have not cloned anything yet.

I know Subversions is perhaps not the best ideal, but to contrast:
   $ svn import http://svn.foo.bar/project/trunk
   $ svn import http://svn.foo.bar/project/branches/1.6

Easy to get to a different branch without having to dive into the full feature set of the SCM.

So, to conclude, I see this as a usability-feature of git-clone, which outweighs the possible risk of introducing new bugs. It's not a feature I will personally use that often, but it's one that I think new users will appreciate.

Tor Arne
Junio C Hamano· Mar 3, 2009, 16:51 UTC · re: Tor Arne Vestbø · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Tor Arne Vestbø <torarnv@gmail.com> writes:
Show 6 quoted lines
> If you would like to contribute to the stable 1.6 branch, do:
>   $ git clone -n git://git.foo.com/project.git
>   $ cd project
>   $ git checkout -t origin/1.6
>   $ git branch -D master
> Which is not so nice and inviting.

If you are working on 1.6 maintenance track, why discard 'master'? If the upstream project calls it 1.6, you can call your fork 1.6 and keep that checked out.

IOW, _you_ are make it not nice.
Tor Arne Vestbø· Mar 3, 2009, 17:04 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Junio C Hamano wrote:
Show 10 quoted lines
> Tor Arne Vestbø <torarnv@gmail.com> writes:
> 
>> If you would like to contribute to the stable 1.6 branch, do:
>>   $ git clone -n git://git.foo.com/project.git
>>   $ cd project
>>   $ git checkout -t origin/1.6
>>   $ git branch -D master
>> Which is not so nice and inviting.
> 
> If you are working on 1.6 maintenance track, why discard 'master'?

One example I can think of is if master is moving a lot faster than the maintenance track, and you are not interested in master.

[box:/tmp/downstream] $ git branch
* 1.6
   master

[box:/tmp/downstream] $ git pull --rebase Current branch 1.6 is up to date.

[box:/tmp/downstream] $ git push
To file:///tmp/upstream
  ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'file:///tmp/upstream'

In that case you would either have to ff master all the time (requiring a checkout or rebase magic), or do an explicit "git push origin 1.6".

Neither good options when you are trying to teach people that git push is the way you submit changes.

Tor Arne
Junio C Hamano· Mar 3, 2009, 17:07 UTC · re: Tor Arne Vestbø · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Tor Arne Vestbø <torarnv@gmail.com> writes:
> In that case you would either have to ff master all the time
> (requiring a checkout or rebase magic), or do an explicit "git push
> origin 1.6".
or do something like:
$ cat >>.git/config <<\EOF
[remote "there"]
    push = HEAD
EOF
just once.
Junio C Hamano· Mar 4, 2009, 06:55 UTC · re: Tor Arne Vestbø · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Tor Arne Vestbø <torarnv@gmail.com> writes:
Show 7 quoted lines
> The options --branch and -b allow the user to override the initial
> branch created and checked out by git-clone (normally this is the
> active branch of the remote repository).
>
> If the selected branch is not found the operation aborts.
>
> Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>

The semantics and desirability of the new feature have been already discussed, and I am not convinced that it is necessary, in the sense that I do not think I likely ever use this myself, but I am just one of git users so that is not a strong basis for rejection.

I'll let others discuss more about the design issues, and will only talk about code in this message.

Show 9 quoted lines
> diff --git a/builtin-clone.c b/builtin-clone.c
> index c338910..5fc01ce 100644
> --- a/builtin-clone.c
> +++ b/builtin-clone.c
> @@ -38,6 +38,7 @@ static int option_quiet, option_no_checkout, option_bare, option_mirror;
>  static int option_local, option_no_hardlinks, option_shared;
>  static char *option_template, *option_reference, *option_depth;
>  static char *option_origin = NULL;
> +static char *option_branch = NULL;

I see this was copied from the line immediately above, but please do not initialize static variables to 0 or NULL. BSS will take care of it.

Show 19 quoted lines
> @@ -372,7 +375,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  	const char *repo_name, *repo, *work_tree, *git_dir;
>  	char *path, *dir;
>  	int dest_exists;
> -	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
> +	const struct ref *refs, *mapped_refs;
> +	const struct ref *remote_head = NULL;
> +	const struct ref *head_points_at = NULL;
>  	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
>  	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
>  	struct transport *transport = NULL;
> @@ -545,12 +550,31 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  
>  		mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
>  
> -		head_points_at = locate_head(refs, mapped_refs, &remote_head);
> +		if (option_branch) {
> +		    const int offset = 11;
> +		    const char *branch = option_branch;
One indent level in git code equals a HT, i.e. 8 places.
> +		    if (!prefixcmp(branch, "refs/heads/"))
> +			branch += offset;

I suspect that you are trying to protect your code against somebody miscounting the length of "refs/heads/" (perhaps when updating this codepath in git version 47 that keeps local branches somewhere else, such as "refs/local-heads/"), but this "const int offset" does not buy you anything. He will likely to leave "offset" to 11 just the same.

It is a different story if it were done like this:
		static const char heads_prefix[] = "refs/heads/";
                if (!prefixcmp(branch, heads_prefix))
                	branch += strlen(heads_prefix);

to let the compiler notice heads_prefix is a constant and optimize the strlen() out, but I personally think it is overkill.

> +		    const struct ref *r;
We do not tolerate decl-after-statement.
Show 8 quoted lines
> +		    for (r = mapped_refs; r; r = r->next) {
> +			if (!strcmp(r->name + offset, branch)) {
> +			    /* Override initial branch */
> +			    head_points_at = r;
> +			    remote_head = r;
> +			    break;
> +			}
> +		    }

This duplicates major part of what locate_head() does but with a different target other than "master", doesn't it?

You would want to refactor this, but I think 'next/pu' already has some refactoring of the locate_head() logic, so you may want to look at it and either build your changes on top of it, or wait until that other topic to stabilize.

Show 6 quoted lines
> +		    if (!head_points_at)
> +			die("remote has no branch named '%s'.", option_branch);
> +
> +		} else {
> +		    head_points_at = locate_head(refs, mapped_refs, &remote_head);
> +		}

This falls into more personal taste than coding guideline, but it often is easier to read to arrange your code:

	if (... condition ...) {
        	shorter codepath
	} else {
        	much
                longer
                code
                path
	}

For one thing, it is much easier to miss a short "else" clause hanging at the end of loooong "if" part.

Johannes Schindelin· Mar 4, 2009, 08:56 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Hi,
On Tue, 3 Mar 2009, Junio C Hamano wrote:
Show 19 quoted lines
> Tor Arne Vestbø <torarnv@gmail.com> writes:
> 
> > +		    if (!prefixcmp(branch, "refs/heads/"))
> > +			branch += offset;
> 
> I suspect that you are trying to protect your code against somebody
> miscounting the length of "refs/heads/" (perhaps when updating this
> codepath in git version 47 that keeps local branches somewhere else, such
> as "refs/local-heads/"), but this "const int offset" does not buy you
> anything.  He will likely to leave "offset" to 11 just the same.
> 
> It is a different story if it were done like this:
> 
> 		static const char heads_prefix[] = "refs/heads/";
>                 if (!prefixcmp(branch, heads_prefix))
>                 	branch += strlen(heads_prefix);
> 
> to let the compiler notice heads_prefix is a constant and optimize the
> strlen() out, but I personally think it is overkill.

Of course you could also do this instead (which I personally think would not be overkill):

		branch = skip_prefix(branch, "refs/heads/");

Ciao, Dscho

Tor Arne Vestbø· Mar 4, 2009, 10:23 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Junio C Hamano wrote:
> I'll let others discuss more about the design issues, and will only talk
> about code in this message.
[...snip...]

Great feedback, much appreciated! :) I'll work up a new patch as soon as I have some free cycles. Thanks!

Tor Arne
Paolo Ciarrocchi· Mar 9, 2009, 14:39 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Junio C Hamano <gitster <at> pobox.com> writes:
Show 15 quoted lines
> 
> Tor Arne Vestbø <torarnv <at> gmail.com> writes:
> 
> > The options --branch and -b allow the user to override the initial
> > branch created and checked out by git-clone (normally this is the
> > active branch of the remote repository).
> >
> > If the selected branch is not found the operation aborts.
> >
> > Signed-off-by: Tor Arne Vestbø <torarnv <at> gmail.com>
> 
> The semantics and desirability of the new feature have been already
> discussed, and I am not convinced that it is necessary, in the sense that
> I do not think I likely ever use this myself, but I am just one of git
> users so that is not a strong basis for rejection.

I wrote a comment about the --branch approach a couple of days ago, dunno why but this thread never reached my inbox (replying via gmame web interface).

http://thread.gmane.org/gmane.comp.version-control.git/112527

As I wrote in my post a friend of mine, new to git, was looking for the possibility of cloning a repo and automatically checkout a specific branch.

Regards,
           Paolo
Felipe Contreras· Mar 9, 2009, 16:01 UTC · re: Paolo Ciarrocchi · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

On Mon, Mar 9, 2009 at 4:39 PM, Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> wrote:

Show 25 quoted lines
> Junio C Hamano <gitster <at> pobox.com> writes:
>
>>
>> Tor Arne Vestbø <torarnv <at> gmail.com> writes:
>>
>> > The options --branch and -b allow the user to override the initial
>> > branch created and checked out by git-clone (normally this is the
>> > active branch of the remote repository).
>> >
>> > If the selected branch is not found the operation aborts.
>> >
>> > Signed-off-by: Tor Arne Vestbø <torarnv <at> gmail.com>
>>
>> The semantics and desirability of the new feature have been already
>> discussed, and I am not convinced that it is necessary, in the sense that
>> I do not think I likely ever use this myself, but I am just one of git
>> users so that is not a strong basis for rejection.
>
> I wrote a comment about the --branch approach a couple of days ago, dunno why
> but this thread never reached my inbox (replying via gmame web interface).
>
> http://thread.gmane.org/gmane.comp.version-control.git/112527
>
> As I wrote in my post a friend of mine, new to git, was looking for the
> possibility of cloning a repo and automatically checkout a specific branch.

Yeah, I also would like this option... one-liner for people that don't know git at all.

me: you want my code? just run this command.
-- 
Felipe Contreras
Paolo Ciarrocchi· Mar 11, 2009, 08:52 UTC · re: Felipe Contreras · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

[restored the CC list]

On Mon, Mar 9, 2009 at 5:01 PM, Felipe Contreras <felipe.contreras@gmail.com> wrote:

> On Mon, Mar 9, 2009 at 4:39 PM, Paolo Ciarrocchi
> <paolo.ciarrocchi@gmail.com> wrote:
[...]
Show 12 quoted lines
>> I wrote a comment about the --branch approach a couple of days ago, dunno why
>> but this thread never reached my inbox (replying via gmame web interface).
>>
>> http://thread.gmane.org/gmane.comp.version-control.git/112527
>>
>> As I wrote in my post a friend of mine, new to git, was looking for the
>> possibility of cloning a repo and automatically checkout a specific branch.
>
> Yeah, I also would like this option... one-liner for people that don't
> know git at all.
>
> me: you want my code? just run this command.
Yes, that is what my friend was lookin for.

I told him to use the following procedure: $ git clone -n URL $ git checkout -b foo origin/bar

He is now an almost happy git user :-).

That being said, I see the following command as an improvement over the actual GIT UI:

 $ git clone git://URI -b bar
Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/
Miles Bader· Mar 12, 2009, 04:18 UTC · re: Paolo Ciarrocchi · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> writes:
Show 7 quoted lines
> $ git clone -n URL
> $ git checkout -b foo origin/bar
>
> That being said, I see the following command as an improvement over
> the actual GIT UI:
>
>  $ git clone git://URI -b bar

Note that in your original advice, foo and bar can be different, and it's not clear to me what "-b bar" should do...

Personally I frequently use foo == bar (no local master branch), but I think another common pattern is foo != bar, but foo or bar == "master".

Maybe a syntax similar to push, like "-b LOCAL_BR:REMOTE_BR", with "-b BR" being shorthand for "-b BR:BR"?

-Miles
-- 
Happiness, n. An agreeable sensation arising from contemplating the misery of
another.
Paolo Ciarrocchi· Mar 12, 2009, 08:48 UTC · re: Miles Bader · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

On Thu, Mar 12, 2009 at 5:18 AM, Miles Bader <miles@gnu.org> wrote:
Show 17 quoted lines
> Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> writes:
>> $ git clone -n URL
>> $ git checkout -b foo origin/bar
>>
>> That being said, I see the following command as an improvement over
>> the actual GIT UI:
>>
>>  $ git clone git://URI -b bar
>
> Note that in your original advice, foo and bar can be different, and
> it's not clear to me what "-b bar" should do...
>
> Personally I frequently use foo == bar (no local master branch), but I
> think another common pattern is foo != bar, but foo or bar == "master".
>
> Maybe a syntax similar to push, like "-b LOCAL_BR:REMOTE_BR",
> with "-b BR" being shorthand for "-b BR:BR"?
Yes, makes sense.
Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/
Felipe Contreras· Mar 12, 2009, 09:12 UTC · re: Paolo Ciarrocchi · lore

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

On Thu, Mar 12, 2009 at 10:48 AM, Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> wrote:

Show 20 quoted lines
> On Thu, Mar 12, 2009 at 5:18 AM, Miles Bader <miles@gnu.org> wrote:
>> Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> writes:
>>> $ git clone -n URL
>>> $ git checkout -b foo origin/bar
>>>
>>> That being said, I see the following command as an improvement over
>>> the actual GIT UI:
>>>
>>>  $ git clone git://URI -b bar
>>
>> Note that in your original advice, foo and bar can be different, and
>> it's not clear to me what "-b bar" should do...
>>
>> Personally I frequently use foo == bar (no local master branch), but I
>> think another common pattern is foo != bar, but foo or bar == "master".
>>
>> Maybe a syntax similar to push, like "-b LOCAL_BR:REMOTE_BR",
>> with "-b BR" being shorthand for "-b BR:BR"?
>
> Yes, makes sense.
+1
-- 
Felipe Contreras

← back to recent threads