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

Re: Quick way to clone exactly one branch

From
Jeff King <peff@peff.net>
Date
May 28, 2009, 20:15 UTC
Message-ID
<20090528201503.GL13499@coredump.intra.peff.net>
In-Reply-To
<32541b130905201345h6daa84e8hb937e1e46456b3c5@mail.gmail.com>
On Wed, May 20, 2009 at 04:45:44PM -0400, Avery Pennarun wrote:
Show 11 quoted lines
> Is there a quick alternative to the following?
> 
>    mkdir myproj
>    cd myproj
>    git init
>    git fetch git://whatever master
>    git checkout -b master FETCH_HEAD
> 
> Basically, the above is a lot like 'git clone' but only clones the
> 'master' branch.  For really big projects with lots of junk in other
> branches, the above can save a lot of bandwidth.

No, AFAIK there isn't a simpler way to do it. But it is something people have asked about before, so I think it would be a nice addition.

You can't even use "git remote" because it doesn't allow you to tweak the refspecs you add. To do it "just like clone" I think you would have to:

  git config remote.origin.url git://whatever
  git config remote.origin.fetch refs/heads/master:refs/remotes/origin/master
It would be nice if that could be:
  git remote add -b master origin git://whatever
and then make it available as:
  git clone -b master git://whatever

Multiple "-b <branch>" options would generate refspecs to pull multiple branches. You could even allow "git clone --refspec=<whatever>", but I don't know what you would use that much flexibility for (and at that point, you are probably comfortable enough to write the config yourself).

-Peff
Previous: Avery PennarunNext: Jakub Narebski
Message 2 of 4 in “Quick way to clone exactly one branch”
  1. Avery PennarunMay 20, 2009
  2. Jeff KingMay 28, 2009
  3. Jakub NarebskiMay 28, 2009
  4. Jeff KingMay 28, 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.