Git fetch objects, no refs

523 Views Asked by At

I want to fetch objects from a remote repo, but not update any local refs. (Yes, I know this is an rather unusual case.)

I see that I can pass a refspec to git fetch, but when I pass an empty one (git fetch my-remote ''), it seems to default to something else because I get the following error:

fatal: Couldn't find remote ref HEAD
fatal: The remote end hung up unexpectedly

Is there a way to specify a "null" ref-spec?

1

There are 1 best solutions below

0
On

To not update any ref you leave part after : in refspec empty:

git fetch origin master:

Then find the commit hash in .git/FETCH_HEAD

Answer to your comment: no, git fetches only objects necessary to get the specified remote ref. The pattern of getting only one branch is commonly used, there is even a dedicated option for git clone for this.

PS: I would instead fetch to a temporary branch with some random name.