Skip to contentSkip to conversation

add --remote option to git-clone.

PATCH In review Michael S. Tsirkin 8 participants 20 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add --remote option to git-clone.

It is sometimes useful to track, and develop against, a single topic branch from the remote repository.
Make this easier to do by adding a flag to git-clone.

---

We have a repository with several long-lived topic branches.

I'm often annoyed by the fact that when I clone from this repository, I get a copy of all topic branches and origin tracking master by default, when I actually might only want to work on a different topic. And getting all extra branches is annoying on a slow connection.

So here's the patch to only get a single branch on clone. Other branches can be added later, on demand.

Junio, what do you think?
I would like very much for git to support this capability.

Documentation/git-clone.txt +6 -2
index 707376f..f66a969 100644
@@ -10,8 +10,8 @@ SYNOPSIS
 --------
 [verse]
 'git-clone' [--template=<template_directory>] [-l [-s]] [-q] [-n] [--bare]
-	  [-o <name>] [-u <upload-pack>] [--reference <repository>]
-	  [--depth=<depth>] <repository> [<directory>]
+	  [-o <name>] [-u <upload-pack>] [--remote <remote-branch>]
+	  [--reference <repository>] [--depth=<depth>] <repository> [<directory>]
 
 DESCRIPTION
 -----------
@@ -84,6 +84,10 @@ OPTIONS
 	Instead of using the remote name 'origin' to keep track
 	of the upstream repository, use <name> instead.
 
+--remote <remote-branch>::
+	When given, only the specified remote branch will be
+	tracked; if unset all remote branches are tracked.
+
 --upload-pack <upload-pack>::
 -u <upload-pack>::
 	When given, and the repository to clone from is handled
git-clone.sh +51 -28

134 lines not on this page · raw message

Signature · 1 line
MST
#1 lore raw
Quoted 4 lines · Michael S. Tsirkin

I'm often annoyed by the fact that when I clone from this repository, I get a copy of all topic branches and origin tracking master by default, when I actually might only want to work on a different topic. And getting all extra branches is annoying on a slow connection.

Can you quantify "annoying"?

Not a challenge, I'm just curious--I would've thought that, for most projects, even with long-lived topic branches, it wouldn't be that expensive to get a second branch once you'd gotten one.

--b.

#2 lore raw
Quoted 11 lines · J. Bruce Fields
Quoted 4 lines · Michael S. Tsirkin

I'm often annoyed by the fact that when I clone from this repository, I get a copy of all topic branches and origin tracking master by default, when I actually might only want to work on a different topic. And getting all extra branches is annoying on a slow connection.

Can you quantify "annoying"?

Not a challenge, I'm just curious--I would've thought that, for most projects, even with long-lived topic branches, it wouldn't be that expensive to get a second branch once you'd gotten one.

Not true; I work on projects like that and some of the branches are several MiB of additional objects beyond the other branches. It can add up very, very fast.

Over slow corporate VPN connections this is definately a problem. Usually the user only wants one branch *right now*. Getting another 15 MiB of data for branches which they aren't interested in could take another 5 minutes. If they do need those, they could always fetch the additional branches later, or do it from the office where the network doesn't suck.

Signature · 1 line
Shawn.
#3 lore raw
In reply to J. Bruce Fields
Quoted 9 lines

Quoting J. Bruce Fields <[email protected]>:
Subject: Re: [PATCH] add --remote option to git-clone.

Quoted 4 lines · Michael S. Tsirkin

I'm often annoyed by the fact that when I clone from this repository, I get a copy of all topic branches and origin tracking master by default, when I actually might only want to work on a different topic. And getting all extra branches is annoying on a slow connection.

Quoted 5 lines

Can you quantify "annoying"?

Not a challenge, I'm just curious--I would've thought that, for most projects, even with long-lived topic branches, it wouldn't be that expensive to get a second branch once you'd gotten one.

Shawn already answered that, I concur.

Signature · 1 line
MST
#4 lore raw
In reply to J. Bruce Fields
Quoted 11 lines · J. Bruce Fields
Quoted 4 lines · Michael S. Tsirkin

I'm often annoyed by the fact that when I clone from this repository, I get a copy of all topic branches and origin tracking master by default, when I actually might only want to work on a different topic. And getting all extra branches is annoying on a slow connection.

Can you quantify "annoying"?

Not a challenge, I'm just curious--I would've thought that, for most projects, even with long-lived topic branches, it wouldn't be that expensive to get a second branch once you'd gotten one.

Regardless of the extra branches, it is also annoying to have the master branch in the clone branched off the HEAD of the parent repo. Especially when you intend to fork an stgit stack off the non-HEAD branch - it will be a pleasure to make "stg clone" to take advantage of this new feature :)

This is also a feature which is available in cogito since ages (cg-clone URL#branch), and not having it in plain git is an annoyance.

Best regards,

Signature · 1 line
Yann.
#6 lore raw
Quoted 4 lines · Johannes Schindelin

would this option not be better named "--branch"? Of course, you'd have to support this, too:

	$ git clone --branch topic1 --branch topic2 git://...

Yes, --branch sounds better here.

Signature · 1 line
Shawn.
#7 lore raw
In reply to Johannes Schindelin
Quoted 6 lines

Quoting Johannes Schindelin <[email protected]>:
Subject: Re: [PATCH] add --remote option to git-clone.

Hi,

would this option not be better named "--branch"?

OK

Quoted 4 lines

Of course, you'd have to
support this, too:

	$ git clone --branch topic1 --branch topic2 git://...

Why is this useful? and which branch to check out? One can always get more branches later, is my approach.

Signature · 1 line
MST
#8 lore raw

Hi,

Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines

Quoting Johannes Schindelin <[email protected]>:
Subject: Re: [PATCH] add --remote option to git-clone.

Of course, you'd have to
support this, too:

	$ git clone --branch topic1 --branch topic2 git://...

Why is this useful?

For the same reasons it might be useful to track _all_ branches.

Quoted 1 line

and which branch to check out?

I'd say the first, but that's just my opinion.

Quoted 1 line

One can always get more branches later, is my approach.

Yes. But in the same vein, one can add _one_ branch to an empty repo either. So, with your reasoning, your patch wouldn't be needed to begin with.

But I find it useful. Even the version where you are not limited to one branch.

Ciao,
Dscho

#9 lore raw
Quoted 7 lines · Johannes Schindelin

On Fri, 2 Feb 2007, Michael S. Tsirkin wrote:
...

Quoted 1 line

One can always get more branches later, is my approach.

Yes. But in the same vein, one can add _one_ branch to an empty repo either. So, with your reasoning, your patch wouldn't be needed to begin with.

Indeed.

Quoted 2 lines

But I find it useful. Even the version where you are not limited to one branch.

I am not against the general idea of tracking a subset of branches, but issues include:

[1] tracking multiple (but not all) branches, as you pointed out,

[2] how this should interact with later fetches from the same remote.

[3] allowing similar "track these branches from a new remote from now on" in an already initialized repository.

Perhaps by specifying the --branch parameter in an wildcard fashion, remote.*.fetch can be initialized to that wildcard and later new branches that match the wildcard pattern ca be fetched (which is a strawman solution for [1] and [2]). I suspect [3] belongs to what "git remote" should allow you to do, but in that case maybe "git init-db ; git remote *that-new-command*" would be a single uniform way to solve all of the above?

I personally feel this is post 1.5.0 material.

#10 lore raw

Hi,

Quoted 12 lines · Junio C Hamano
Quoted 7 lines · Johannes Schindelin

On Fri, 2 Feb 2007, Michael S. Tsirkin wrote:
...

Quoted 1 line

One can always get more branches later, is my approach.

Yes. But in the same vein, one can add _one_ branch to an empty repo either. So, with your reasoning, your patch wouldn't be needed to begin with.

Indeed.

Quoted 7 lines
Quoted 2 lines

But I find it useful. Even the version where you are not limited to one branch.

I am not against the general idea of tracking a subset of branches, but issues include:

[explains why git-remote is a better place for this]

Seeing your patch to git-remote, it feels more natural, too. Especially since that (or which? :-D) does not give the term "clone" a Microsoft'esque completely new meaning.

Ciao,
Dscho

#11 lore raw
Quoted 10 lines · Johannes Schindelin

On Thu, 1 Feb 2007, Junio C Hamano wrote:
...

Quoted 4 lines

I am not against the general idea of tracking a subset of branches, but issues include:

[explains why git-remote is a better place for this]

Seeing your patch to git-remote, it feels more natural, too. Especially since that (or which? :-D) does not give the term "clone" a Microsoft'esque completely new meaning.

I did not find anything MS'esque in what MST did in his patch, though. I think it is a reasonable thing to ask for from a clone. For example, if you are coming from CVS or have used Cogito, cloning a single branch is not an unusual operation at all.

The real point of my 'remote add -f -t -m' patch is that I think we are much better off to do it in a bottom up way, by having a tool that can be used in any repository first. Then we could even rewrite 'git clone' along these lines:

#/bin/sh
track="*" ;# command line parameter to override... ... decide what $name to use ...
mkdir "$name"
cd "$name"
git init-db
git remote add -f -t "$track" origin $url git branch -f master remotes/origin/master

Of course you would need to deal with -n, --bare and stuff, but that is a minor detail.

While I am talking about post 1.5.0 git-clone changes, one thing I've always hated about git-clone is that the cloner always has to guess where the HEAD pointer at the other side points at. This comes from a shortcoming in the fetch-pack protocol (it simply does not tell). A stupid consequence of this is that cloning over dumb protocols also have to guess, although they are _capable_ of letting the cloner know this information.

I think the logic to decide where to point remotes/$origin/HEAD to should be moved to "git-remote add -m" when we eventually rewrite "git-clone" to use "git-remote add -f". And while we would do so, we can make a trivial extension to fetch-pack protocol to carry the HEAD symref information. All will be good once that happens.

#12 lore raw

Hi,

Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Johannes Schindelin

On Thu, 1 Feb 2007, Junio C Hamano wrote:
...

Quoted 4 lines

I am not against the general idea of tracking a subset of branches, but issues include:

[explains why git-remote is a better place for this]

Quoted 8 lines
Quoted 3 lines

Seeing your patch to git-remote, it feels more natural, too. Especially since that (or which? :-D) does not give the term "clone" a Microsoft'esque completely new meaning.

I did not find anything MS'esque in what MST did in his patch, though. I think it is a reasonable thing to ask for from a clone. For example, if you are coming from CVS or have used Cogito, cloning a single branch is not an unusual operation at all.

Oh? Well, to me, "clone" meant something like the genetics thing, i.e. get a copy of the repository. Since a "branch" is not the complete repository, but only part of it, I would have expected "engraft" instead of "clone" there.

But I can learn! So (post-1.5.0, maybe?) I'd be perfectly d'accord with something like this

	git clone git://.../git.git#html

to mean "just fetch the branch html, and check it out".

Quoted 14 lines

The real point of my 'remote add -f -t -m' patch is that I think we are much better off to do it in a bottom up way, by having a tool that can be used in any repository first. Then we could even rewrite 'git clone' along these lines:

#/bin/sh
track="*" ;# command line parameter to override... ... decide what $name to use ...
mkdir "$name"
cd "$name"
git init-db
git remote add -f -t "$track" origin $url git branch -f master remotes/origin/master

Quoted 2 lines

Of course you would need to deal with -n, --bare and stuff, but that is a minor detail.

Yeah, that makes sense.

Quoted 8 lines

While I am talking about post 1.5.0 git-clone changes, one thing I've always hated about git-clone is that the cloner always has to guess where the HEAD pointer at the other side points at. This comes from a shortcoming in the fetch-pack protocol (it simply does not tell). A stupid consequence of this is that cloning over dumb protocols also have to guess, although they are _capable_ of letting the cloner know this information.

Quoted 5 lines

I think the logic to decide where to point remotes/$origin/HEAD to should be moved to "git-remote add -m" when we eventually rewrite "git-clone" to use "git-remote add -f". And while we would do so, we can make a trivial extension to fetch-pack protocol to carry the HEAD symref information. All will be good once that happens.

Would you like this as a multi_ack-like extension?

But then how to teach the dumb protocols in a backwards-compatible fashion?

Ciao,
Dscho

#13 lore raw
Quoted 11 lines · Johannes Schindelin

Oh? Well, to me, "clone" meant something like the genetics thing, i.e. get a copy of the repository. Since a "branch" is not the complete repository, but only part of it, I would have expected "engraft" instead of "clone" there.

But I can learn! So (post-1.5.0, maybe?) I'd be perfectly d'accord with something like this

	git clone git://.../git.git#html

to mean "just fetch the branch html, and check it out".

I agree that the word "clone" to me sounds like "copy the whole repo", so a single branch cloning feels it is something different from "clone", but I do not think it means wholeness must be the only mode of operation.

Except that I do not particularly think the URL fragment notation is such a "cool" syntax.

Quoted 10 lines
Quoted 5 lines

I think the logic to decide where to point remotes/$origin/HEAD to should be moved to "git-remote add -m" when we eventually rewrite "git-clone" to use "git-remote add -f". And while we would do so, we can make a trivial extension to fetch-pack protocol to carry the HEAD symref information. All will be good once that happens.

Would you like this as a multi_ack-like extension?

But then how to teach the dumb protocols in a backwards-compatible fashion?

I am not talking about enhancing ls-remote output nor info/refs file format. I do not think we need to do anything special to support it in backwards compatible way.

Look at what dumb protocols do in git-clone. http already knows where HEAD points at when it fetches HEAD with curl. I do not particularly care about rsync, but I suspect it can be handled the same way.

#14 lore raw
Quoted 8 lines
Quoted 4 lines · Junio C Hamano

Johannes Schindelin <[email protected]> writes:

	git clone git://.../git.git#html

to mean "just fetch the branch html, and check it out".

Except that I do not particularly think the URL fragment notation is such a "cool" syntax.

OK, but I think it would be very good I think to have *some* URL-like syntax for git-fetch etc - people are used to copying URLs out of mail (lots of MUAs even highlight these nicely) so I often see that current syntax <URL> <branch> confuses
people: they seem to lose the branch and fetch/pull the wrong one.

Signature · 1 line
MST
#15 lore raw
In reply to Junio C Hamano
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
	git clone git://.../git.git#html

to mean "just fetch the branch html, and check it out".

Except that I do not particularly think the URL fragment notation is such a "cool" syntax.

I think the cogito '#'<branch> syntax is braindead.

Much better to use native git syntax, which is to just list the branch separately. Why? Not only is it the way we do things for pull and friends, it's also what allows us to specify *multiple* branches.

So I would personally welcome a "clone just a particular branch", but in that case I'd like it to be able to say more than one too..

(In general, even if I clone _everything_, I'd also like to perhaps set the default 'master' branch to track something else than what I'm cloning from. In fact, I think I'd generally prefer cloning everything, but sometimes I'd like to say "I'm going to track the upstreams branch xyzzy rather than their default branch").

I realize that the

git clone <repo> [<dir>]

means that we can't have the same syntax as "git pull" (which doesn't take the <dir> part), but that doesn't make the "#branch" syntax any better.

So I much prefer the

git clone [--default branch] [--branch x]* <repo> [<dir>

kind of syntax.

Linus

#16 lore raw
Quoted 10 lines

(In general, even if I clone _everything_, I'd also like to perhaps set the default 'master' branch to track something else than what I'm cloning from. In fact, I think I'd generally prefer cloning everything, but sometimes I'd like to say "I'm going to track the upstreams branch xyzzy rather than their default branch").

I realize that the

git clone <repo> [<dir>]

Quoted 8 lines

means that we can't have the same syntax as "git pull" (which doesn't take the <dir> part), but that doesn't make the "#branch" syntax any better.

So I much prefer the

git clone [--default branch] [--branch x]* <repo> [<dir>

kind of syntax.

Two questions:
- I understand --branch is too large for 1.5.0, but maybe this --default isn't?
- Or, maybe we can have a flag to avoid creating the master branch at all? User can combine this with -n, then check which branches exist with "git branch -r" and create the branch himself.

Signature · 1 line
MST
#17 lore raw
In reply to Linus Torvalds
Quoted 4 lines · Linus Torvalds

I realize that the

git clone <repo> [<dir>]

Quoted 8 lines

means that we can't have the same syntax as "git pull" (which doesn't take the <dir> part), but that doesn't make the "#branch" syntax any better.

So I much prefer the

	git clone [--default branch] [--branch x]* <repo> [<dir>]

kind of syntax.

Ugh. That means the bash completion cannot (easily) do something fancy, like tab completion of branch names within <repo>. Yea, its not fast on slow links, but it beats typing out an ugly branch name. :-)

Signature · 1 line
Shawn.
#18 lore raw
In reply to Junio C Hamano
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Johannes Schindelin

On Thu, 1 Feb 2007, Junio C Hamano wrote:
...

Quoted 4 lines

I am not against the general idea of tracking a subset of branches, but issues include:

[explains why git-remote is a better place for this]

Seeing your patch to git-remote, it feels more natural, too. Especially since that (or which? :-D) does not give the term "clone" a Microsoft'esque completely new meaning.

Quoted 5 lines

I did not find anything MS'esque in what MST did in his patch, though. I think it is a reasonable thing to ask for from a clone. For example, if you are coming from CVS or have used Cogito, cloning a single branch is not an unusual operation at all.

But when we clone whole repository we could have download whole object database of cloned repo as-is (perhaps packing loose objects in smart/git-aware transports).

By the way, there was discussed idea about marking pu-like branches as being rewound (non-fast forwarding) in the config file, and somehow transferring this information for git-clone for it to have '+' for some refspecs. What happened to that idea? Was it abandoned because reflogs are now enabled by default, are protected from pruning, and it is easy to recover from accidental non-fast forward fetch which shouldn't be?

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#19 lore raw
Quoted 9 lines · Jakub Narebski
Quoted 5 lines

I did not find anything MS'esque in what MST did in his patch, though. I think it is a reasonable thing to ask for from a clone. For example, if you are coming from CVS or have used Cogito, cloning a single branch is not an unusual operation at all.

But when we clone whole repository we could have download whole object database of cloned repo as-is (perhaps packing loose objects in smart/git-aware transports).

I think your point is if you have branches A and B, cloning A+B as a whole is a lot less expensive than cloning A and then B separately. While that is true, I do not think that reasoning would apply to somebody, especially behind a slow link, who is only interested in A. She does not want to pay the cost of A+B, when she only wants A, even if A+B is much less expensive than twice the cost of getting A.

Also, if she later gets interested in B, git fetch will make the "what's common" optimization. It won't be like cloning A and then fetching B into the same repository later would be twice as expensive compared to the case where you start from a clone as a whole. The overall transfer cost would probably be comparable.

Quoted 4 lines

By the way, there was discussed idea about marking pu-like branches as being rewound (non-fast forwarding) in the config file, and somehow transferring this information for git-clone for it to have '+' for some refspecs. What happened to that idea? Was it abandoned...

Well, I would not call some idle talk without a concrete design (preferably with a proof-of-concept code, but that is not an absolute requirement) "idea". Something that did not even start cannot get abandoned ;-).

I thought that it would not hurt to have something like that, but because in 1.5.0 "git clone" creates fetch configuration of 'forcing' kind by default, I do not think it makes that much of a difference.