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

Re: [RFC PATCH] Allow cloning branches selectively

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 23, 2011, 21:18 UTC
Message-ID
<7vmxajaswj.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1324671199-7074-1-git-send-email-cmn@elego.de>
Carlos Martín Nieto <cmn@elego.de> writes:
> Sometimes it's useful to clone only a subset of branches from a remote
> we're cloning. Teach clone the --fetch option to select which branches
> should get fetched.

This is just a knee-jerk reaction without reading the patch text (which I won't be doing over the holiday weekend anyway), but is the workflow of the primarly intended audience to clone "a subset of branches" or "a single branch"?

I have a slight suspicion that this started out as "I often want to create a clone to _track_ a single branch, but because I am mucking with the code related to cloning anyway, I might as well allow more than one to be fetched, even though I do not have any need for that, somebody might find it useful". And that is why it is important to answer the first question.

If the primary motivation is for a single branch, I suspect supporting only a single branch and advertising the feature as "tracking only one branch" might make it much easier to understand to the end users.

Upon "git clone --track cn/single-clone $there x.git", you would do something like:

  it=cn/single-clone &&
  git init x.git &&
  cd x.git &&
  # configure "git fetch origin" to only get branch $it
  git config remote.origin.url "$there" &&
  git config remote.origin.fetch refs/heads/$it:refs/remotes/origin/$it &&
  # declare that the primary branch at origin is $it as far as we are concerned
  git symbolic-ref -m clone refs/remotes/origin/HEAD refs/remotes/origin/$it &&
  # Git aware prompt reminds us that this repository is to track branch $it
  git symbolic-ref -m clone HEAD refs/heads/$it &&
  # And Go!
  git fetch origin &&
  git reset --hard remotes/origin/$it &&
  git config branch.$it.remote origin &&
  git config branch.$it.merge $it

Of course you _could_ support more than one pretty easily, but the point is that it is unclear how you explain to the end user what the feature does and what it is for in easily understoodd terms, once you start doing so. It will no longer be "this new clone is to track that branch", but something else, and I do not know what that something else is.

And depending on what that "something else" is, which branch should be checked out and what refs/remotes/origin/HEAD should name as the primary branch of the remote would be different.

Thanks.
Previous: Carlos Martín NietoNext: Carlos Martín Nieto
Message 2 of 7 in “Allow cloning branches selectively”
  1. Allow cloning branches selectivelyCarlos Martín Nieto, Dec 23, 2011
  2. Junio C HamanoDec 23, 2011
  3. Carlos Martín NietoDec 25, 2011
  4. Nguyen Thai Ngoc DuyDec 24, 2011
  5. Carlos Martín NietoDec 25, 2011
  6. Jakub NarebskiDec 25, 2011
  7. Carlos Martín NietoDec 25, 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.