git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Working with remotes; cloning remote references

From
Marc Branchaud <marcnarc@xiplink.com>
Date
Oct 21, 2008, 15:17 UTC
Message-ID
<48FDF28A.9060606@xiplink.com>
In-Reply-To
<48FDA5A0.8030506@drmicha.warpmail.net>
Michael J Gruber wrote:
Show 7 quoted lines
>
>> clone/$ git config remote.origin.fetch \
>>          '+refs/remotes/ThingOne/*:refs/remotes/ThingOne/*'
> 
> If you want to fetch main's local branches also, use option "--add" here
> so that you don't override the default fetch refspec (forgot last time,
> sorry).
Okay, got it.
> I thought you wanted to avoid pulling directly from ThingOne to clone?

Ah, I see (part of) our disconnect here -- sorry for not explaining it clearly before!

Yes, indeed, I do want to pull directly from ThingOne into the clone.

The scenario is that there's a bunch of us sharing the main repo, and when some upstream changes happen in ThingOne I'd like for one of us to be able to clone the main repo, pull the changes from ThingOne into the clone (fixing any conflicts; remember that we have our own changes in ThingOne's code), then push the merged changes back to main for everyone else to grab.

> If you pull directly you might as well set up the same remote config as
> on main: for the correct pull line you need to know the same info as for
> the correct remote config.
Yes, I see that -- it's why I'm basically satisfied with being able to do
	clone/$ git pull -s subtree /path/to/ThingOne master

from the clone, and all I'm doing now is kvetching about having to remember the location and branch of ThingOne when that was already configured in main (and thanks for being patient with my kvetching!).

> git fetch
> git merge -s subtree remotes/ThingOne/master
> 
> should do the trick.

AFAICT that only refers to the clone's local branch for the ThingOne repo. The above git-config command doesn't add the ThingOne repo's URL to the clone, so I'm still stuck having to use that URL directly to pull changes from ThingOne into the clone. (And when I use the URL directly, I have to use a branch name that's defined in the ThingOne repo. I'd like to also be able to use whatever branch name got set up in main when "git remote add" was run.)

Show 8 quoted lines
> If that works you can set up things so that pulling
> from origin (pulling when you're in your integration branch) does that
> merge automatically, using branch.integrationbranch.remote=origin,
> branch.integrationbranch.merge=remotes/ThingOne/master (untested ;) ).
> 
> To be clear: The idea here is that main decides which ThingOne branch to
> store in remotes/ThingOne/master and where to get it from; clones always
> pull that one.

I think that "where to get it from" part is what I'm going on about. There doesn't seem to be a way for the main repo to tell the clone where the ThingOne repo is, so that the clone can pull in ThingOne changes directly.

Show 8 quoted lines
>> I just feel that there are some 
>> situations where you want the origin's remotes in your clone, and some 
>> where you don't, and git should let you decide.
> 
> Well, it let's you decide: It tracks local branches by default, and
> using additional "git config" you can track remotes as well. You can
> also use the "--mirror" option to "git clone" or "git remote add", but
> that has other side effects.

I think we're mis-communicating, mainly because I'm not yet able to express things well in git-speak. Let me give it another stab...

I believe git lets you track the origin's _branches_ not the origin's _remotes_. I don't think --mirror does what I'm looking for, because (side effects aside) it only deals with branches, not remotes.

I find myself getting confused, and I think it's because the files in 
.git/refs/remotes/ are indeed tracking branches on remote repositories. 
  So I think our conversation gets a bit circular because our ideas of a 
"remote" differ.

"git remote add" does two things (maybe more?): It adds a [remote] section to the .git/config file, and it adds a branch reference in .git/refs/remotes/. I think what I'd like is for the clone to be able to obtain both these things from the origin. The reason I think it's useful is that it would let the clone pull directly from the origin's remote repositories, without having to directly specify the remote repository's URL and branch name.

Fundamentally, I'm looking to do exactly
	clone/$ git pull -s subtree /path/to/ThingOne master

i.e. pull stuff from one of main's remotes directly into the clone. But I want to replace the "/path/to/ThingOne master" part with something that means "use whatever URL and branch name was defined in the origin for this remote".

My questions are: Am I right in thinking this is desirable? Is there already some way to do this? If not, is it something worth implementing? (I'm happy to roll up my own sleeves here...)

I hope that clarifies things.  Sorry for taking so long to get here!
		Marc
Previous: Michael J GruberNext: Michael J Gruber
Message 13 of 24 in “Working with remotes; cloning remote references”
  1. Marc BranchaudOct 16, 2008
  2. Peter HarrisOct 16, 2008
  3. Marc BranchaudOct 16, 2008
  4. Peter HarrisOct 16, 2008
  5. Marc BranchaudOct 16, 2008
  6. Michael J GruberOct 17, 2008
  7. Marc BranchaudOct 17, 2008
  8. Michael J GruberOct 17, 2008
  9. Marc BranchaudOct 17, 2008
  10. Michael J GruberOct 20, 2008
  11. Marc BranchaudOct 20, 2008
  12. Michael J GruberOct 21, 2008
  13. Marc BranchaudOct 21, 2008
  14. Michael J GruberOct 22, 2008
  15. Terminology question: "tracking" branchesBjörn Steinbrink, Oct 22, 2008
  16. Michael J GruberOct 23, 2008
  17. Marc BranchaudOct 27, 2008
  18. Björn SteinbrinkOct 27, 2008
  19. Johannes SchindelinOct 27, 2008
  20. Björn SteinbrinkOct 27, 2008
  21. Björn SteinbrinkOct 28, 2008
  22. Marc BranchaudOct 27, 2008
  23. Michael J GruberOct 28, 2008
  24. Marc BranchaudOct 28, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.