13 years later, you now have With a prefetch
task in "git maintenance
"(man)
The prefetch task updates the object directory with the latest objects from all registered remotes.
For each remote, a git fetch
command is run.
The refmap is custom to avoid updating local or remote branches (those in refs/heads
or refs/remotes
).
Instead, the remote refs are stored in refs/prefetch/<remote>/
.
Also, tags are not updated.
This is done to avoid disrupting the remote-tracking branches.
The end users expect these refs to stay unmoved unless they initiate a fetch.
With prefetch task, however, the objects necessary to complete a later real fetch would already be obtained, so the real fetch would go faster.
In the ideal case, it will just become an update to a bunch of remote-tracking branches without any object transfer.
And you can also do, since Git 2.32 (Q2 2021) a git fetch --prefetch
, again without modifying your last fetch state.
See commit 32f6788, commit cfd781e, commit 2e03115 (16 Apr 2021), and commit a039a1f (06 Apr 2021) by Derrick Stolee (derrickstolee
).
(Merged by Junio C Hamano -- gitster
-- in commit d250f90, 30 Apr 2021)
fetch
: add --prefetch
option
Helped-by: Tom Saeger
Helped-by: Ramsay Jones
Signed-off-by: Derrick Stolee
The --prefetch
option will be used by the 'prefetch' maintenance task instead of sending refspecs explicitly across the command-line.
The intention is to modify the refspec to place all results in refs/prefetch/
instead of anywhere else.
Create helper method filter_prefetch_refspec()
to modify a given refspec to fit the rules expected of the prefetch task:
- Negative refspecs are preserved.
- Refspecs without a destination are removed.
- Refspecs whose source starts with "
refs/tags/
" are removed.
- Other refspecs are placed within "
refs/prefetch/
".
Finally, we add the 'force
' option to ensure that prefetch refs are replaced as necessary.
There are some interesting cases that are worth testing.
An earlier version of this change dropped the "i--
" from the loop that deletes a refspec item and shifts the remaining entries down.
This allowed some refspecs to not be modified.
The subtle part about the first --prefetch
test is that the refs/tags/*
refspec appears directly before the refs/heads/bogus/* refspec.
Without that "i--
", this ordering would remove the "refs/tags/*
" refspec and leave the last one unmodified, placing the result in "refs/heads/*
".
It is possible to have an empty refspec.
This is typically the case for remotes other than the origin, where users want to fetch a specific tag or branch.
To correctly test this case, we need to further remove the upstream remote for the local branch.
Thus, we are testing a refspec that will be deleted, leaving nothing to fetch.
fetch-options
now includes in its man page:
--prefetch
Modify the configured refspec to place all refs into the
refs/prefetch/
namespace.