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

Re: [RFC] git clone add option to track all remote branches

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 2, 2018, 09:29 UTC
Message-ID
<874lkuvtve.fsf@evledraar.gmail.com>
In-Reply-To
<20180402015035.mzgye6apwn3igch5@HP>
On Mon, Apr 02 2018, Yubin Ruan wrote:
Show 8 quoted lines
> I am writing to ask that whether or not you think will be appropriate to add
> an option to "git clone" so that whenever a repo is cloned, branches are
> created automatically to track corresponding remote branches. (or is there any
> equivelant option?)
>
> You can obviously do this by a bash command like this
>
>     git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

Aside from this specific suggestion, we should be careful when adding more special snowflakes to git-clone that aren't available through git-fetch or via after the fact config, such as git clone --single-branch which has no fetch equivalent (i.e. in finding out what the remote HEAD is).

Actually now that I mention that it occurs to me that what you want could just be a special case of generalizing our existing --single-branch feature. I.e. we would clone repos as:

    [remote "origin"]
    url = git@github.com:git/git.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    branch = $symref(HEAD):refs/remotes/origin/HEAD:TRACK

Or some other such syntax to create a refs/heads/master from the remote HEAD symref if it doesn't exist (note the lack of a +), then for your feature:

    branch = refs/heads/*:refs/remotes/origin/*:TRACK
But you could also do:
    branch = +refs/heads/origin/*:refs/remotes/origin/*:TRACK

Or whatever. I don't know what syntax would be sensible, but something like this is a missing feature of our existing --single-branch feature, and because of that you can only get its semantics by re-cloning.

Previous: Randall S. Becker
Message 5 of 5 in “[RFC] git clone add option to track all remote branches”
  1. Yubin RuanApr 2, 2018
  2. Junio C HamanoApr 2, 2018
  3. Junio C HamanoApr 2, 2018
  4. Randall S. BeckerApr 2, 2018
  5. Ævar Arnfjörð BjarmasonApr 2, 2018

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.