How to git fetch and prune only a subset of exactly specified refs

60 Views Asked by At

I want to synchronize certain subset of custom refs from origin to the local copy:

git fetch --force --prune origin refs/x/1:refs/x/1 refs/x/3:refs/x/3

I need git fetch to delete local ref when the remote one is missing. However, git fetch fails when any ref is missing on the remote: fatal: couldn't find remote ref refs/x/... and the existing refs are not fetched.

Workarounds

  1. Fetch ref one by one, delete local ref on error. But it's slow for many refs.
  2. Append * to refs and use --prune param:
    git fetch --force --prune origin refs/x/1*:refs/x/1* refs/x/3*:refs/x/3*
    
    Drawback is, that it may fetch unnecessary refs, too (like refs/x/11 etc.)

Is there any better way how to make git fetch synchronize subset of remote refs?

0

There are 0 best solutions below