{"thread":{"id":"59538","subject":"mirror clone does not keep HEAD updated","startedAt":"2023-04-04T16:26:09Z","lastAt":"2023-04-05T01:56:34Z","messageCount":4,"participants":["Daniel Martí","Junio C Hamano","Felipe Contreras"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"474788","messageId":"harpgnimhcdp2m6hww7ht7pgxvchllvrncnwoxkivaorb5xhm7@5rcr2p7hcp4x","threadId":"59538","inReplyTo":null,"subject":"mirror clone does not keep HEAD updated","fromName":"Daniel Martí","fromEmail":"mvdan@mvdan.cc","sentAt":"2023-04-04T16:16:57Z","receivedAt":"2023-04-04T16:26:09Z","isPatch":false,"sender":{"key":"mvdan@mvdan.cc","avatar":"https://gravatar.com/avatar/1bc6b62398685e34778bf7a80afc728d6d42da3a88f50e91a643e2c7065f7a8c?d=mp&s=160"},"body":"Hello all,\n\nI'm testing `git clone --mirror` to properly mirror a repository on\ngithub.com. It appears to be working well, except for keeping HEAD\ncorrectly in place.\n\nFor example, here is what I did:\n\n\t$ git clone --mirror https://github.com/mvdan/test-repo\n\t$ cd test-repo\n\t$ git branch -a\n\t* main\n\t$ git log HEAD\n\tcommit d1adda533e90692e02ae837233368fbcca2a0e49 (HEAD -> main)\n\t[...]\n\nIf I then go on the GitHub web UI to rename the default branch from\n\"main\" to \"newmain\", `git remote update --prune` sees that:\n\n\t$ git remote update --prune\n\tFrom https://github.com/mvdan/test-repo\n\t - [deleted]         (none)     -> main\n\t * [new branch]      newmain   -> newmain\n\nHowever, HEAD stops working:\n\n\t$ git log HEAD\n\tfatal: your current branch 'main' does not have any commits yet\n\nAm I holding the mirror wrong somehow? As far as the manpages say, `git\nremote update` should be enough to fully mirror all refs.\nAnd my understanding is that using HEAD is correct, that I do not need\nto use origin/HEAD like in a regular git clone.\n\nI also tried what I would usually do to sync origin/HEAD in a regular\ngit clone, but unsurprisingly, that does not work:\n\n\t$ git remote set-head origin -a\n\terror: Not a valid ref: refs/remotes/origin/newmain\n\nAny pointers appreciated. Assuming I'm not missing anything obvious\nhere, this might be a bug in `git remote udpate` for mirror clones.\n"},{"id":"474789","messageId":"xmqqileb1u34.fsf@gitster.g","threadId":"59538","inReplyTo":"harpgnimhcdp2m6hww7ht7pgxvchllvrncnwoxkivaorb5xhm7@5rcr2p7hcp4x","subject":"Re: mirror clone does not keep HEAD updated","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-04T16:38:07Z","receivedAt":"2023-04-04T16:38:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Martí <mvdan@mvdan.cc> writes:\n\n> I'm testing `git clone --mirror` to properly mirror a repository on\n> github.com. It appears to be working well, except for keeping HEAD\n> correctly in place.\n\nThere is no such feature in \"git clone\" or \"git fetch\" to check what\nbranch the remote HEAD is pointing at and move the local copy around.\nFor a long time, even \"git clone\" did not have a reliable way to see\nwhere the HEAD at the remote site points at, and it used heuristics\nto guess what name to give to the first branch on the local side.\n\nModern versions of Git these days have a protocol level support to\nconvey that information, and I think it is feasible to invent such a\nfeature to automatically repoint refs/remotes/$remote/HEAD to\nwhatever remote-tracking branch found in the refs/remotes/$remote/\nhierarchy.\n\nI do not think anybody is working on such a project, though.\n\nWe are pretty much \"somebody should initiate the process to scratch\ntheir own itch, and we will help them in doing so\" community, so you\nor somebody who reads this thread interesting will hopefully start\nsuch an effort ;-)\n\nThanks.\n"},{"id":"474819","messageId":"CAMP44s1TBUmc6mhGSWQ1v+E5_VRqnCUXURHs2cM-vE22eyndsQ@mail.gmail.com","threadId":"59538","inReplyTo":"harpgnimhcdp2m6hww7ht7pgxvchllvrncnwoxkivaorb5xhm7@5rcr2p7hcp4x","subject":"Re: mirror clone does not keep HEAD updated","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-05T01:38:33Z","receivedAt":"2023-04-05T01:38:48Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Tue, Apr 4, 2023 at 11:35 AM Daniel Martí <mvdan@mvdan.cc> wrote:\n>\n> I'm testing `git clone --mirror` to properly mirror a repository on\n> github.com. It appears to be working well, except for keeping HEAD\n> correctly in place.\n\nGit does not set or update the remote HEAD, that's something the user\nis supposed to do (for some reason).\n\nThe only exception is when cloning a repository.\n\nIn my opinion this is completely unintuitive and unhelpful. 99.99% of\nthe time I want the remote HEAD to be pointing to where the remote's\nHEAD is pointing to.\n\nI implemented patches to fix that [1], but they were never merged.\n\nIt's particularly wrong when you are mirroring a repository, as in your case.\n\n> Am I holding the mirror wrong somehow? As far as the manpages say, `git\n> remote update` should be enough to fully mirror all refs.\n\nThat's what I would expect, but that's not true.\n\nI find that most of the time I need to read git's code to actually\nunderstand what it's supposed to do. I don't bother reading the\ndocumentation.\n\nI've updated my old RFC patch adding tests and an option to make it\nwork with mirrored repositories as well. With\n`fetch.updateHead=always` the mirrored clone always has the HEAD\nup-to-date.\n\nCheers.\n\n[1] https://lore.kernel.org/git/20201118091219.3341585-1-felipe.contreras@gmail.com/\n[2] https://lore.kernel.org/git/20230405012742.2452208-1-felipe.contreras@gmail.com/T/#ma012c4823814936a3ab8755d1d2b805d61b43133\n\n-- \nFelipe Contreras\n"},{"id":"474820","messageId":"CAMP44s1DrFY7ZxfdFwVDd=uJpdxkEDf8irAzEKmcih2MEuv0Aw@mail.gmail.com","threadId":"59538","inReplyTo":"xmqqileb1u34.fsf@gitster.g","subject":"Re: mirror clone does not keep HEAD updated","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-05T01:56:18Z","receivedAt":"2023-04-05T01:56:34Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Tue, Apr 4, 2023 at 12:07 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Daniel Martí <mvdan@mvdan.cc> writes:\n>\n> > I'm testing `git clone --mirror` to properly mirror a repository on\n> > github.com. It appears to be working well, except for keeping HEAD\n> > correctly in place.\n>\n> There is no such feature in \"git clone\" or \"git fetch\" to check what\n> branch the remote HEAD is pointing at and move the local copy around.\n\nOnly because you didn't merge the patches I sent a while ago [1].\n\n> Modern versions of Git these days have a protocol level support to\n> convey that information, and I think it is feasible to invent such a\n> feature to automatically repoint refs/remotes/$remote/HEAD to\n> whatever remote-tracking branch found in the refs/remotes/$remote/\n> hierarchy.\n\nOr just repoint it to the remote's HEAD, which is what everyone expects.\n\n> We are pretty much \"somebody should initiate the process to scratch\n> their own itch, and we will help them in doing so\" community, so you\n> or somebody who reads this thread interesting will hopefully start\n> such an effort ;-)\n\nThat has not been my experience. Even when I scratch somebody else's\nitch, there is not much help, and the patches don't end up being\nmerged.\n\nCheers.\n\n[1] https://lore.kernel.org/git/20201118091219.3341585-1-felipe.contreras@gmail.com/\n\n-- \nFelipe Contreras\n"}]}