# Per-remote tracking branch

6 messages from 2009-09-15 to 2009-09-24. Participants: Matthieu Moy, Jeff King, Björn Steinbrink.
Thread: https://gitlist.dev/t/20956

## Matthieu Moy, 2009-09-15 15:29

Subject: Per-remote tracking branch
Message-ID: <vpq4or48bux.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq4or48bux.fsf%40bauges.imag.fr

```
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, 2009-09-24 06:29

Subject: Re: Per-remote tracking branch
Message-ID: <20090924062911.GC24486@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090924062911.GC24486%40coredump.intra.peff.net
In-Reply-To: <vpq4or48bux.fsf@bauges.imag.fr>

```
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, 2009-09-24 11:10

Subject: Re: Per-remote tracking branch
Message-ID: <vpq63b8egy7.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq63b8egy7.fsf%40bauges.imag.fr
In-Reply-To: <20090924062911.GC24486@coredump.intra.peff.net>

```
Hi, and thanks for your answer,

Jeff King <peff@peff.net> writes:

> 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 ;-).

> 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, 2009-09-24 11:25

Subject: Re: Per-remote tracking branch
Message-ID: <20090924112550.GA6540@atjola.homenet>
URL: https://gitlist.dev/e/20090924112550.GA6540%40atjola.homenet
In-Reply-To: <vpq4or48bux.fsf@bauges.imag.fr>

```
On 2009.09.15 17:29:58 +0200, Matthieu Moy wrote:
> 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, 2009-09-24 11:35

Subject: Re: Per-remote tracking branch
Message-ID: <20090924113537.GA14113@atjola.homenet>
URL: https://gitlist.dev/e/20090924113537.GA14113%40atjola.homenet
In-Reply-To: <20090924112550.GA6540@atjola.homenet>

```
On 2009.09.24 13:25:50 +0200, Björn Steinbrink wrote:
> 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, 2009-09-24 16:00

Subject: Re: Per-remote tracking branch
Message-ID: <vpqskec5o54.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqskec5o54.fsf%40bauges.imag.fr
In-Reply-To: <20090924113537.GA14113@atjola.homenet>

```
Björn Steinbrink <B.Steinbrink@gmx.de> writes:

>> 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/

```
