threads / discuss / 40379

default remote branch

Subject: default remote branch

## tl;dr

2 messages between Sep 18, 2015 and Sep 21, 2015.

replies: 1people: 2as markdown or json

Thibault Kruse· Sep 18, 2015, 09:50 UTC · lore
Hi,

the 'git remote show <remote>' command shows the default branch among other things. The default branch being the branch that a clone will have immediately after cloning.

Is it possible to run a command that only shows that default branch for a given remote?

Also, I tried finding out whether I can use the .git/refs/remotes/<remote>/HEAD to check the default branch without accessing the remote. However, I find this file is not updated with a git fetch, nor created when missing.

So is there a sane way to get the last know default branch without accessing the remote? If so, is there a way to update local information about the default branch of a remote?

cheers,
  Thibault
Junio C Hamano· Sep 21, 2015, 17:16 UTC · re: Thibault Kruse · lore

Re: default remote branch

Thibault Kruse <tibokruse@googlemail.com> writes:
> Also, I tried finding out whether I can use the
> .git/refs/remotes/<remote>/HEAD to check the default branch without
> accessing the remote. However, I find this file is not updated with a
> git fetch, nor created when missing.

That is more or less deliberate. Which one of the branches to consider the primary one becomes a local decision after you clone. If that was a good choice may be debatable, but that is how existing users expect things to work.

> So is there a sane way to get the last know default branch without
> accessing the remote?

"The last known" is not updated, due to "where remotes/origin/HEAD points at is a local matter" design; there is nothing that locally stores the information you are asking for, so there is no offline way to answer that question.

An early part of the protocol exchange "git clone" does carry that information, but I do not think there is a command to ask that to the remote. A logical place to add it would be a new option to "git ls-remote", I would think.

← back to recent threads