When a repository is initialized locally (not cloned), and has a remote added afterwards, the git symbolic-ref --short refs/remotes/origin/HEAD command fails with an error:
fatal: ref refs/remotes/origin/HEAD is not a symbolic ref
In our current get_default_branch code, we then fall back to running symbolic-ref HEAD --short. However, this is not correct.
For example, a local repository can have a completely different branch checked out locally, so the symbolic-ref HEAD --short does not return the default branch.
When a repository is initialized locally (not cloned), and has a remote added afterwards, the
git symbolic-ref --short refs/remotes/origin/HEAD
command fails with an error:fatal: ref refs/remotes/origin/HEAD is not a symbolic ref
In our current
get_default_branch
code, we then fall back to runningsymbolic-ref HEAD --short
. However, this is not correct. For example, a local repository can have a completely different branch checked out locally, so thesymbolic-ref HEAD --short
does not return the default branch.Related issue.