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

Re: Working with remotes; cloning remote references

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Oct 21, 2008, 09:49 UTC
Message-ID
<48FDA5A0.8030506@drmicha.warpmail.net>
In-Reply-To
<48FCB6B8.6090708@xiplink.com>
Marc Branchaud venit, vidit, dixit 10/20/08 18:50:
Show 18 quoted lines
> Thanks for the explicit instructions, but I think I'm still missing 
> something.  Here's exactly what I'm trying, just to make sure I'm not 
> doing something odd.
> 
> First I set up the remote in the main repo:
> 
> main/$ git remote add -f ThingOne git://thing/ThingOne.git
> main/$ git merge -s ours --no-commit ThingOne/master
> main/$ git read-tree --prefix=thing-one/ -u ThingOne/master
> main/$ git commit -m "Adding ThingOne"
> 
> Then I make a clone, fetch main's refs to ThingOne, and try to pull in 
> changes from ThingOne by using those refs:
> 
> $ git clone /path/to/main clone
> $ cd clone
> 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).

Show 6 quoted lines
> clone/$ git fetch
>  From /path/to/main/
>   * [new branch]      ThingOne/master -> ThingOne/master 
> 
> clone/$ git pull -s subtree git://thing/ThingOne.git ThingOne/master
> fatal: Couldn't find remote ref ThingOne/master
because on ThingOne there is no such ref.
> The config & fetch commands indeed add a 
> .git/refs/remotes/ThingOne/master file to the clone, but I'm missing the 
> magic words for how to use that ref.

I thought you wanted to avoid pulling directly from ThingOne to clone? 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.

git fetch git merge -s subtree remotes/ThingOne/master

should do the trick. 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.

Show 29 quoted lines
> Also:
> 
> Michael J Gruber wrote:
>>> And actually, git's remote functionality feels a bit crippled if clones 
>>> can't make some use of the origin's remotes.  Is there a reason for 
>>> keeping remote definitions out of a clone?
>> Say A and B are working on a project C. Then, typically, A is interested
>> in B's work on C, i.e. some of B's local branches, but not on B's remote
>>  tracking branches: A tracks a "central" C already, just like B does,
>> and remote tracking branches don't carry any "value adding" by the
>> cloner, they're just a local unmodified copy of the remote.
> 
> I can appreciate that, but the approach leads to two consequences that I 
> suggest should be avoidable:
> 
> 1. A and B both have to set up the references to C themselves.  A can't 
> just piggyback on whatever B has already set up.  (This is the impetus 
> for my original message.)
> 
> 2. Suppose B is just a repository that's being shared between A and D -- 
> i.e. there's no B entity doing any work directly in B.  In this case if 
> A (or D) wants to change B's reference to C (say, to track a new branch 
> in C), they can't: B has to be changed directly, and nothing can be done 
> in a clone to accomplish this.
> 
> I admit I'm picking at nits here -- obviously someone is able to access 
> the B repo and do whatever needs doing.  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.

Cheers, Michael

Previous: Marc BranchaudNext: Marc Branchaud
Message 12 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.