threads / discuss / 20956

Per-remote tracking branch

Subject: Per-remote tracking branch

## tl;dr

6 messages between Sep 15, 2009 and Sep 24, 2009.

replies: 5people: 3as markdown or json

Matthieu Moy· Sep 15, 2009, 15:29 UTC · lore
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,
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Jeff King· Sep 24, 2009, 06:29 UTC · re: Matthieu Moy · lore

Re: Per-remote tracking branch

On Tue, Sep 15, 2009 at 05:29:58PM +0200, Matthieu Moy wrote:
> 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
Matthieu Moy· Sep 24, 2009, 11:10 UTC · re: Jeff King · lore

Re: Per-remote tracking branch

Hi, and thanks for your answer,
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
> On Tue, Sep 15, 2009 at 05:29:58PM +0200, Matthieu Moy wrote:
>
>> 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
I had tried this in case it would have worked ;-).
Show 5 quoted 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 ;-).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Björn Steinbrink· Sep 24, 2009, 11:25 UTC · re: Matthieu Moy · lore

Re: Per-remote tracking branch

On 2009.09.15 17:29:58 +0200, Matthieu Moy wrote:
Show 23 quoted lines
> 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?

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
Björn Steinbrink· Sep 24, 2009, 11:35 UTC · re: Björn Steinbrink · lore

Re: Per-remote tracking branch

On 2009.09.24 13:25:50 +0200, Björn Steinbrink wrote:
Show 27 quoted lines
> On 2009.09.15 17:29:58 +0200, Matthieu Moy wrote:
> > 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?
> 
> 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
Matthieu Moy· Sep 24, 2009, 16:00 UTC · re: Björn Steinbrink · lore

Re: Per-remote tracking branch

Björn Steinbrink <B.Steinbrink@gmx.de> writes:
Show 13 quoted 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.
Yes, that's it. Thanks for your anwser, it works.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads