Per-remote tracking branch

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Per-remote tracking branch

Matthieu Moy-2
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/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: Per-remote tracking branch

Jeff King
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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: Per-remote tracking branch

Matthieu Moy-2
Hi, and thanks for your answer,

Jeff King <[hidden email]> 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/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: Per-remote tracking branch

Björn Steinbrink
In reply to this post by Matthieu Moy-2
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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: Per-remote tracking branch

Björn Steinbrink
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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: Per-remote tracking branch

Matthieu Moy-2
Björn Steinbrink <[hidden email]> 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/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html