Per-remote tracking branch
Hi,
Is there a way, with Git, to specify a tracking branch on a per-remote basis?
At the moment, I can configure a tracking branch to let me just type
$ git pull
when I want to say
$ git pull origin master
Now, assume I have another remote "foo", I'd like to be able to just say
$ git pull foo
and put something in my .git/config so that Git knows I mean
$ git pull foo master
Is there a simple way to do that?
(for the motivation: I mostly use Git with a 1-branch-per-repo setup, so in 99% of my use-cases, when I have to specify a branch, it's master).
Thanks,
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 2 lines · Matthieu Moy
Is there a way, with Git, to specify a tracking branch on a per-remote basis?
I don't think so, and I'm not sure there is an easy way to extend the current configuration scheme. Adding multiple config options like this:
[branch "master"]
remote = origin
merge = refs/heads/master
remote = alternate
merge = refs/heads/master
looks a bit hack-ish to me, as there is an implicit correlation between the ordering of 'merge' entries and 'remote' entries.
And it feels a little backwards. When I say "git pull foo", I would find it equally likely to discover the pulled branch under "remote.foo" as it would to find it under "branch.master". Of course, in either case, you have to combine the context (current branch _and_ selected remote) to come up with the actual information. So I guess either is "equally correct" in a sense.
Anyway, mostly just my idle speculation.
-Peff
Hi, and thanks for your answer,
Quoted 5 lines · Jeff King
Quoted 2 lines · Matthieu Moy
Is there a way, with Git, to specify a tracking branch on a per-remote basis?
Quoted 8 lines
I don't think so, and I'm not sure there is an easy way to extend the current configuration scheme. Adding multiple config options like this:
[branch "master"]
remote = origin
merge = refs/heads/master
remote = alternate
merge = refs/heads/master
I had tried this in case it would have worked ;-).
Quoted 5 lines
And it feels a little backwards. When I say "git pull foo", I would find it equally likely to discover the pulled branch under "remote.foo" as it would to find it under "branch.master". Of course, in either case, you have to combine the context (current branch _and_ selected remote) to come up with the actual information.
Actually, for my particular use case (aka "almost always only one branch per repo"), I could as well have a remote.foo.defaultBranch regardless of the current local branch. Then, if I say "git pull foo", it would understand it as "git pull foo <remote.foo.defaultBranch>".
If other people would be interested in such feature, say so, I may give it a try when I have time. If I'm the only one, I guess I'll let my fingers type the extra " master" instead ;-).
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 16 lines · Matthieu Moy
Hi,
Is there a way, with Git, to specify a tracking branch on a per-remote basis?
At the moment, I can configure a tracking branch to let me just type
$ git pullwhen I want to say
$ git pull origin masterNow, assume I have another remote "foo", I'd like to be able to just say
Quoted 7 lines
$ git pull fooand put something in my .git/config so that Git knows I mean
$ git pull foo masterIs there a simple way to do that?
Setup "foo" so that it fetches "master" only, i.e. have remote.foo.fetch = refs/heads/master:refs/remotes/foo/master
You get that setup with: git remote add -t master foo git://...
Then there's only one possible choice for "git pull", and it will take that.
Björn
Quoted 20 lines · Björn Steinbrink
Quoted 11 lines · Matthieu Moy
At the moment, I can configure a tracking branch to let me just type
$ git pullwhen I want to say
$ git pull origin masterNow, assume I have another remote "foo", I'd like to be able to just say
Quoted 7 lines
$ git pull fooand put something in my .git/config so that Git knows I mean
$ git pull foo masterIs there a simple way to do that?
Quoted 7 lines
Setup "foo" so that it fetches "master" only, i.e. have remote.foo.fetch = refs/heads/master:refs/remotes/foo/master
You get that setup with: git remote add -t master foo
git://...Then there's only one possible choice for "git pull", and it will take that.
Ah, crap, spoke too soon. That works only when branch.<name>.merge is not set. Though that's not that much of a problem. When your "primary" remote (the one set for branch.<name>.remote) also fetches just a single branch, "git pull" will still work, even if branch.<name>.merge is not set.
Björn
Quoted 5 lines · Björn Steinbrink
Quoted 5 lines
Setup "foo" so that it fetches "master" only, i.e. have remote.foo.fetch = refs/heads/master:refs/remotes/foo/master
You get that setup with: git remote add -t master foo
git://...
Quoted 8 lines
Quoted 2 lines
Then there's only one possible choice for "git pull", and it will take that.
Ah, crap, spoke too soon. That works only when branch.<name>.merge is not set. Though that's not that much of a problem. When your "primary" remote (the one set for branch.<name>.remote) also fetches just a single branch, "git pull" will still work, even if branch.<name>.merge is not set.
Yes, that's it. Thanks for your anwser, it works.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/