How to `git fetch` the default branch

Viewed 72

I'm writing a generic script which fetches some branches from a set of remote repositories, and I'd like it to only fetch some of the branches. For most of the branches, this is easy because they're specified by name and I can just write a corresponding refspec, but I haven't found a way to fetch "the default branch".

I tried to pass to git fetch a refspec of the form refs/heads/HEAD:MY/LOCAL/BRANCH but that tells me:

fatal: couldn't find remote ref refs/heads/HEAD

How can I specify "the default branch" in a refspec? Currently, I just hardcode master, but of course that only works on those repositories which stick to this default.

1 Answers
Related