Page MenuHomePhabricator

In Git repositories, use "git symbolic-ref HEAD ..." to select the default branch

Authored by epriestley on Apr 16 2019, 1:31 PM.



Depends on D20434. Fixes T5963. Broadly, the issue here is that when:

  • You create a new, empty repository.
  • Then, you work on some branch other than master, without ever creating master. get a warning on git clone:

warning: remote HEAD refers to nonexistent ref, unable to checkout

To fix this, point the symbolic-ref HEAD at refs/heads/<default-branch> after installing commit hooks.

This fixes the warning, and also means that git clone will check out the repository default branch by default, which is nice.

There are a few caveats about this behavior (see T5963 for discussion) but nothing too substantial.

The only real issue is that Git prevents deletion of the default branch without a config setting. Just set that settting.

Test Plan

See T5963.

In a repository, set HEAD to point somewhere invalid. Ran bin/repository update .... Saw HEAD pointed back at the repository default branch.

Diff Detail

rP Phabricator
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

epriestley created this revision.Apr 16 2019, 1:31 PM
epriestley requested review of this revision.Apr 16 2019, 1:33 PM
epriestley updated this revision to Diff 48740.Apr 16 2019, 2:07 PM
  • Do this for both hosted and observed repositories. It's not super common to clone from Phabricator's copy of an observed repository, but it does happen sometimes and we might as well be consistent.
  • Ran bin/repository update ... for both hosted and observed repositories, saw config/symbolic-ref in both cases.
epriestley retitled this revision from In hosted Git repositories, use "git symbolic-ref HEAD ..." to select the default branch to In Git repositories, use "git symbolic-ref HEAD ..." to select the default branch.Apr 16 2019, 2:35 PM
amckinley accepted this revision.Apr 17 2019, 9:17 PM
amckinley added inline comments.


This revision is now accepted and ready to land.Apr 17 2019, 9:17 PM
This revision was automatically updated to reflect the committed changes.
epriestley added inline comments.Apr 18 2019, 1:01 PM

Oops, missed this. I'll get it in a followup.