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"; doneAside 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:TRACKOr 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.