gitgit-pushgit-clonegit-fetchgit-clone--reference

How does `--reference-if-able` affect `git fetch` and `git push` propagation in a clone?


I have two local clones of the same remote repository (urlA):

  1. mirror/ – created with
    git clone --mirror urlA mirror
    
  2. dirB/ – created with
    git clone --reference-if-able ../mirror urlA dirB
    

In dirB, when I run:

git fetch
git push

will mirror/ be updated by either command?

My understanding is that --reference-if-able only speeds up object downloads by reusing objects from the reference repo, and does not turn the reference into an actual remote that receives fetch or push. However, I found elsewhere a comment suggesting it might propagate commands.

Question:
Does --reference[-if-able] ever trigger fetch or push on the reference repository? If not, how can I configure Git so that a single git push or git fetch from dirB also updates my local mirror clone?


Solution

  • --reference / --reference-if-able does:

    When you clone with --reference or --reference-if-able, Git borrows object data from the reference repository (in this case, ../mirror). This is only for performance/memory efficiency — it helps to avoid downloading or storing duplicate objects.

    --reference / --reference-if-able does not:

    So no, git fetch or git push in dirB will not update mirror/. mirror/ remains completely unaware of what happens in dirB.

    If you want mirror/ to be updated automatically when you fetch/push from dirB, you'll need to explicitly configure that behavior with a custom script or a hook.