{"thread":{"id":"63588","subject":"Fetch remote only if remote hasn't been fetched recently","startedAt":"2025-06-05T11:17:04Z","lastAt":"2025-07-01T07:00:48Z","messageCount":8,"participants":["M Hickford","Konstantin Ryabitsev","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"519765","messageId":"CAGJzqskDumbMSbC3rdYT8fZ8gNJ5MOjR_o8RAo9QS-nuvbBinQ@mail.gmail.com","threadId":"63588","inReplyTo":"CAGJzqs=kJtPcMrWC8Dayd+VW7BvC1rmzS0zT+EwQXfLOpZ3Tfg@mail.gmail.com","subject":"Fetch remote only if remote hasn't been fetched recently","fromName":"M Hickford","fromEmail":"mirth.hickford@gmail.com","sentAt":"2025-06-05T11:16:26Z","receivedAt":"2025-06-05T11:17:04Z","isPatch":false,"sender":{"key":"mirth.hickford@gmail.com","avatar":"https://avatars.githubusercontent.com/u/105314?v=4"},"body":"Hi. I'd like to fetch from a particular remote, but only if that\nremote hasn't been fetched in the last hour. How could I achieve this?\nIs there a relevant option for `git fetch`?\n\nhttps://git-scm.com/docs/git-fetch\n"},{"id":"519771","messageId":"20250605-flying-lemon-junglefowl-4c1d64@lemur","threadId":"63588","inReplyTo":"CAGJzqskDumbMSbC3rdYT8fZ8gNJ5MOjR_o8RAo9QS-nuvbBinQ@mail.gmail.com","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2025-06-05T14:02:40Z","receivedAt":"2025-06-05T14:02:44Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Thu, Jun 05, 2025 at 12:16:26PM +0100, M Hickford wrote:\n> Hi. I'd like to fetch from a particular remote, but only if that\n> remote hasn't been fetched in the last hour. How could I achieve this?\n> Is there a relevant option for `git fetch`?\n\nNot to my knowledge, but you can either look at the timestamp of FETCH_HEAD\n(if that's the only remote you're fetching), or wrap git-fetch in a small\nscript that touches .git/last-fetched-foo file and you can then check that\nfile and exit if it's newer than 1 hour ago.\n\n-K\n"},{"id":"519797","messageId":"xmqqtt4u86x2.fsf@gitster.g","threadId":"63588","inReplyTo":"CAGJzqskDumbMSbC3rdYT8fZ8gNJ5MOjR_o8RAo9QS-nuvbBinQ@mail.gmail.com","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-05T16:55:21Z","receivedAt":"2025-06-05T16:55:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"M Hickford <mirth.hickford@gmail.com> writes:\n\n> Hi. I'd like to fetch from a particular remote, but only if that\n> remote hasn't been fetched in the last hour. How could I achieve this?\n> Is there a relevant option for `git fetch`?\n>\n> https://git-scm.com/docs/git-fetch\n\n\"git fetch\" is \"I want to fetch now\".  If you want to pace your\nfetches, you have to keep a record of when you fetched in the past\nand work from there.\n\nI sense there perhaps is an XY problem?\n\nIf \"git fetch\" is done outside end-user's supervision and explicit\nintent, the remote-tracking branches will become much less useful to\nthe human users.  A good solusion that avoids this issue already\nexists as the \"prefetch\" task of the \"git maintenance\" suite.\n"},{"id":"519884","messageId":"CAGJzqsksmQmY4o-_7DoPFK8VP-h59ANUjroVv2+++ZG3gDBdUA@mail.gmail.com","threadId":"63588","inReplyTo":"xmqqtt4u86x2.fsf@gitster.g","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"M Hickford","fromEmail":"mirth.hickford@gmail.com","sentAt":"2025-06-07T07:00:00Z","receivedAt":"2025-06-07T07:01:55Z","isPatch":false,"sender":{"key":"mirth.hickford@gmail.com","avatar":"https://avatars.githubusercontent.com/u/105314?v=4"},"body":"On Thu, 5 Jun 2025 at 17:55, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> M Hickford <mirth.hickford@gmail.com> writes:\n>\n> > Hi. I'd like to fetch from a particular remote, but only if that\n> > remote hasn't been fetched in the last hour. How could I achieve this?\n> > Is there a relevant option for `git fetch`?\n> >\n> > https://git-scm.com/docs/git-fetch\n>\n> \"git fetch\" is \"I want to fetch now\".  If you want to pace your\n> fetches, you have to keep a record of when you fetched in the past\n> and work from there.\n>\n> I sense there perhaps is an XY problem?\n>\n> If \"git fetch\" is done outside end-user's supervision and explicit\n> intent, the remote-tracking branches will become much less useful to\n> the human users.  A good solusion that avoids this issue already\n> exists as the \"prefetch\" task of the \"git maintenance\" suite.\n\nInteresting, thank you.\n\nSuppose my network connection is intermittent. While the machine is\nonline, `git fetch --prefetch` runs successfully. Later I am offline.\nHow can I complete the fetch?\n"},{"id":"519970","messageId":"xmqqtt4puhwq.fsf@gitster.g","threadId":"63588","inReplyTo":"CAGJzqsksmQmY4o-_7DoPFK8VP-h59ANUjroVv2+++ZG3gDBdUA@mail.gmail.com","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-09T14:08:21Z","receivedAt":"2025-06-09T14:08:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"M Hickford <mirth.hickford@gmail.com> writes:\n\n> Interesting, thank you.\n>\n> Suppose my network connection is intermittent. While the machine is\n> online, `git fetch --prefetch` runs successfully. Later I am offline.\n> How can I complete the fetch?\n\nI _think_ that it uses \"git fetch --prefetch\" to store what is\nusually stored at refs/$R to refs/prefetch/$R (so your\nremote-tracking branch refs/remotes/origin/frotz is stored at\nrefs/prefetch/remotes/origin/frotz instead), so I would presume that\nit should be the matter of doing something silly like this:\n\n    $ git fetch . 'refs/prefetch/remotes/origin/*:refs/remotes/origin/*'\n\n"},{"id":"520076","messageId":"CAGJzqs=Xur+=0=KUSR6TQA-A3zt-Bpyd5-T52_ntuV+mCUrAQA@mail.gmail.com","threadId":"63588","inReplyTo":"xmqqtt4puhwq.fsf@gitster.g","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"M Hickford","fromEmail":"mirth.hickford@gmail.com","sentAt":"2025-06-11T07:00:00Z","receivedAt":"2025-06-11T07:00:29Z","isPatch":false,"sender":{"key":"mirth.hickford@gmail.com","avatar":"https://avatars.githubusercontent.com/u/105314?v=4"},"body":"On Mon, 9 Jun 2025 at 15:08, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> M Hickford <mirth.hickford@gmail.com> writes:\n>\n> > Interesting, thank you.\n> >\n> > Suppose my network connection is intermittent. While the machine is\n> > online, `git fetch --prefetch` runs successfully. Later I am offline.\n> > How can I complete the fetch?\n>\n> I _think_ that it uses \"git fetch --prefetch\" to store what is\n> usually stored at refs/$R to refs/prefetch/$R (so your\n> remote-tracking branch refs/remotes/origin/frotz is stored at\n> refs/prefetch/remotes/origin/frotz instead), so I would presume that\n> it should be the matter of doing something silly like this:\n>\n>     $ git fetch . 'refs/prefetch/remotes/origin/*:refs/remotes/origin/*'\n>\n\nThanks, that worked.\n\nTo support Git users with sporadic connectivity, might it be useful to\nadd an option to git fetch? Perhaps  `git fetch --offline` or `git\nfetch --complete-prefetch`?\n\nhttps://git-scm.com/docs/git-fetch\n"},{"id":"520105","messageId":"xmqqjz5ijo97.fsf@gitster.g","threadId":"63588","inReplyTo":"CAGJzqs=Xur+=0=KUSR6TQA-A3zt-Bpyd5-T52_ntuV+mCUrAQA@mail.gmail.com","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-11T15:23:32Z","receivedAt":"2025-06-11T15:23:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"M Hickford <mirth.hickford@gmail.com> writes:\n\n>>     $ git fetch . 'refs/prefetch/remotes/origin/*:refs/remotes/origin/*'\n>>\n>\n> Thanks, that worked.\n>\n> To support Git users with sporadic connectivity, might it be useful to\n> add an option to git fetch? Perhaps  `git fetch --offline` or `git\n> fetch --complete-prefetch`?\n\n\"offline catch-up\" is probably the phrase I would prefer to see in\nthe documentation page to explain the concept of the operation than\n\"complete prefetch\".\n\n\"complete prefetch\" sounds like an oxymoron, in that the prefetch\nhas already been completed long ago, and the operation being\nproposed is more about using the result of that operation completed\nlong ago to get yourself closer to the present state of the remote\nwithout any guarantees that you would end up being close enough.\n\nIn any case, to present it as a first-class option to end-users,\nthere needs a lot more thinking and a bit of work need to go into\nthe way \"prefetch\" works.  For example, the longhand I gave would\nwork as a good solution only when the user _knows_ that the prefetch\nis more recent than their actual remote-tracking branches.  If\nrefs/prefetch/remotes/R/* is older, then you wouldn't be bringing\nyourself closer to the present state of the remote at all with such\na fetch, but as far as I know, a normal \"git fetch R\" from the\nremote R would not clear refs/prefetch/remotes/R/* when it\ncompletes.  There is no \"last time we fetched from there\" record\nkept anywhere in the repository either.  So offhand, you'd at least\nneed to do these:\n\n - teach \"git fetch\" that updates remote-tracking branches to remove\n   the corresponding ref in the refs/prefetch/ hierarchy;\n\n - decide on what option name to use for this new operation and\n   document it;\n\n - implement the option \"git fetch --that-option nickname\" to\n\n   - figure out the remote-tracking hierarchy for nickname and call\n     it R\n\n   - when refs/prefetch/remotes/R/* exists, do an\n\n     $ git fetch . \"+refs/prefetch/remotes/R/*:refs/remotes/R/*\"\n\n"},{"id":"520991","messageId":"CAGJzqskku=BSx_rZx0EgLLS-E2uJKLxu0rfqkKFTVSJ3Su749A@mail.gmail.com","threadId":"63588","inReplyTo":"xmqqjz5ijo97.fsf@gitster.g","subject":"Re: Fetch remote only if remote hasn't been fetched recently","fromName":"M Hickford","fromEmail":"mirth.hickford@gmail.com","sentAt":"2025-07-01T07:00:00Z","receivedAt":"2025-07-01T07:00:48Z","isPatch":false,"sender":{"key":"mirth.hickford@gmail.com","avatar":"https://avatars.githubusercontent.com/u/105314?v=4"},"body":"On Wed, 11 Jun 2025 at 16:23, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> M Hickford <mirth.hickford@gmail.com> writes:\n>\n> > To support Git users with sporadic connectivity, might it be useful to\n> > add an option to git fetch? Perhaps  `git fetch --offline` or `git\n> > fetch --complete-prefetch`?\n>\n> \"offline catch-up\" is probably the phrase I would prefer to see in\n> the documentation page to explain the concept of the operation than\n> \"complete prefetch\".\n\nThat makes sense to me.\n\n> In any case, to present it as a first-class option to end-users,\n> there needs a lot more thinking and a bit of work need to go into\n> the way \"prefetch\" works.  For example, the longhand I gave would\n> work as a good solution only when the user _knows_ that the prefetch\n> is more recent than their actual remote-tracking branches.  If\n> refs/prefetch/remotes/R/* is older, then you wouldn't be bringing\n> yourself closer to the present state of the remote at all with such\n> a fetch, but as far as I know, a normal \"git fetch R\" from the\n> remote R would not clear refs/prefetch/remotes/R/* when it\n> completes.  There is no \"last time we fetched from there\" record\n> kept anywhere in the repository either.  So offhand, you'd at least\n> need to do these:\n>\n>  - teach \"git fetch\" that updates remote-tracking branches to remove\n>    the corresponding ref in the refs/prefetch/ hierarchy;\n>\n>  - decide on what option name to use for this new operation and\n>    document it;\n>\n>  - implement the option \"git fetch --that-option nickname\" to\n>\n>    - figure out the remote-tracking hierarchy for nickname and call\n>      it R\n>\n>    - when refs/prefetch/remotes/R/* exists, do an\n>\n>      $ git fetch . \"+refs/prefetch/remotes/R/*:refs/remotes/R/*\"\n>\n\nThanks Junio for your insight.\n\nI shall leave this as a feature request, perhaps suitable for a\nmicroproject #leftoverbits\n"}]}