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

Re: [PATCH v2] Add --track option to git clone

From
Jeff King <peff@peff.net>
Date
Dec 2, 2009, 19:08 UTC
Message-ID
<20091202190807.GB30778@coredump.intra.peff.net>
In-Reply-To
<20091202192028.6117@nanako3.lavabit.com>
On Wed, Dec 02, 2009 at 07:20:28PM +0900, Nanako Shiraishi wrote:
Show 14 quoted lines
> Quoting David Soria Parra <sn_@gmx.net> writes:
> 
> > I'm aware that it's not possible to give more than one --track
> > option. Implementing the possibility to specify multiple --track option
> > would certainly a good improvment later, but would also require a lot
> > more work as far as I understand the clone code.
> 
> I'm sorry if I'm asking the obvious, but how can multiple --track 
> options be a useful future enhancement? If I understand your use 
> case correctly, it's useful when you want to work on only one 
> branch that isn't the default, and that is why you don't want to 
> get data necessary for other branches. What does it mean to give 
> two --track options? You will get one master branch that tracks
> both versions, and "git pull" will merge both branches you track?

I would find something like this useful for cloning git.git, where I explicitly fetch maint, master, next, and pu, but none of html, man, or todo. This makes "gitk --all" much nicer to view.

However, I don't think --track is the right term. There are really two things happening here:

  1. Setting the fetch refspec(s).
  2. Choosing an initial branch to checkout.

We can already do (2) with "-b". But there is no way to do (1) currently. If we are going to implement (1), I don't see a reason to be restrictive about it. We should really accept arbitrary refspecs, and then provide a syntax on top of that for doing both (1) and (2) together. I am thinking something like:

  # most general case
  git clone -f 'refs/heads/subset/*:refs/remotes/origin/*' remote.git
  # expands to refs/heads/subset/*:refs/remotes/origin/*
  git clone -f 'refs/heads/subset/*' remote.git
  # expands to refs/heads/subset/*, which then expands as above
  git clone -f 'subset/*' remote.git
  # multiple -f should add multiple refspec lines
  git clone -f maint -f master -f next -f pu git.git
  # choose your favorite branch
  git clone -f maint -f master -f next -f pu -b next git.git

And for convenience of the user, you would want a way to avoid repeating the name of the "I want to check this out" branch. So either:

  1. Add "--track foo" as a convenience wrapper for "-f foo -b foo".
  2. If no "-b" is given, the first "-f" is assumed as "-b". So "git
     clone -f foo" becomes equivalent to David's --track.

And of course the name "-f" (for --fetch, if you were wondering) is open to suggestion.

What do you think?
-Peff
Previous: David Soria ParraNext: David Soria Parra
Message 8 of 13 in “Add --track option to git clone”
  1. Add --track option to git cloneDavid Soria Parra, Dec 1, 2009
  2. 1/2 Teach clone to clone just one remote branch using --trackDavid Soria Parra, Dec 1, 2009
  3. 2/2 Documentation: Add --track option to the git clone manpageDavid Soria Parra, Dec 1, 2009
  4. Sean EstabrooksDec 2, 2009
  5. David Soria ParraDec 2, 2009
  6. Nanako ShiraishiDec 2, 2009
  7. David Soria ParraDec 2, 2009
  8. Jeff KingDec 2, 2009
  9. David Soria ParraDec 2, 2009
  10. Nanako ShiraishiDec 2, 2009
  11. Jeff KingDec 2, 2009
  12. Junio C HamanoDec 2, 2009
  13. Björn SteinbrinkDec 3, 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.