From: Mirochnik, Oleg V Date: Wed, 25 Dec 2024 17:23:13 GMT Subject: "git fetch" fails for a --reference clone after an outer forced push Message-ID: Hi all, To reduce traffic, we use local mirrors via "git clone --reference mirror ..." commands. And we regularly get problems with update of few weeks old clones and must run something like below to get rid of outdated branches: git for-each-ref --format="%(refname)" | while read ref; do git show-ref --quiet --verify $ref 2>/dev/null || git update-ref -d $ref done This can be quite long operation as number of refs is significant. Details are below. Thanks, Oleg. Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue. What did you do before the bug happened? (Steps to reproduce your issue) $ cat ./doit #!/bin/sh set -xe rm -rf tst mkdir tst cd tst mkdir master git -C master init --bare git clone master local touch local/foo git -C local add . git -C local commit -m init-commit git -C local push echo foo > local/foo git -C local commit -a -m dummy-commit git -C local push origin HEAD:refs/heads/dummy git clone --mirror file://`pwd`/master mirror git clone --reference `pwd`/mirror file://`pwd`/master local1 git -C local1 log --oneline origin/dummy git -C local commit --amend -m new-dummy-commit git -C local push -f origin HEAD:dummy git -C mirror fetch git -C mirror gc --prune=now git -C local1 fetch git -C local1 log --oneline origin/dummy What did you expect to happen? (Expected behavior) No errors; last few lines like: + git -C local1 fetch From file:///tmp/tst/master + 552a293...248c7fa dummy -> origin/dummy (forced update) + git -C local1 log --oneline origin/dummy 248c7fa (origin/dummy) new-dummy-commit 0636429 (HEAD -> master, origin/master, origin/HEAD) init-commit What happened instead? (Actual behavior) + git -C local1 fetch fatal: bad object refs/remotes/origin/dummy error: file:///tmp/tst/master did not send all necessary objects What's different between what you expected and what actually happened? Obvious - should work and does not work Anything else you want to add: It works if "git -C mirror gc --prune=now" step is skipped or if local path is used for the clone steps instead of the "file://" The same issue is with https://github.com/... The same issue if use "git -C local1 remote update --prune" instead of the "git -C local1 fetch" Please review the rest of the bug report below. You can delete any lines you don't wish to share. podman ub24 container is used to get a newer git version. Exactly the same behavior is for the git v2.39.1 [System Info] git version: git version 2.43.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.14.0-70.13.1.el9_0.x86_64 #1 SMP PREEMPT Thu Apr 14 12:42:38 EDT 2022 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): [Enabled Hooks] not run from a git repository - no hooks to show