Skip to content

Setting "Default Branch" does not update the symbolic ref in .git/HEAD #7601

Closed
@vg-c

Description

@vg-c

Description

When a repository uses a default branch whose name is not "master", Gitea still maintains the .git/HEAD file with the content: "ref: refs/heads/master", and even if you try to explicitly set or update the default branch using the Settings/Branches page, it does not change the content of the HEAD file. Consequently, when you try to clone such a repository on your local machine, you get a warning from git: "warning: remote HEAD refers to nonexistent ref, unable to checkout." and then you have to explicitly checkout the default branch of the repository.

Exact steps to reproduce the issue are given below (tested and confirmed on https://try.gitea.io/vg-c/testdefaultbranch):

$ mkdir testdefaultbranch
$ cd testdefaultbranch
$ git init
$ touch README
$ git add README
$ git commit
$ git branch -m master newbranch
$ git branch -vv

  • newbranch e2b1ee7 init commit
    $ cat .git/HEAD
    ref: refs/heads/newbranch

$ git remote add origin https://try.gitea.io/vg-c/testdefaultbranch.git
$ git push -u origin newbranch
...
Counting objects: 3, done.
Writing objects: 100% (3/3), 192 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://try.gitea.io/vg-c/testdefaultbranch.git

  • [new branch] newbranch -> newbranch
    Branch newbranch set up to track remote branch newbranch from origin.

$ cd ..
$ mkdir t
$ cd t
$ git clone https://try.gitea.io/vg-c/testdefaultbranch.git
Cloning into 'testdefaultbranch'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

$ cat testdefaultbranch/.git/HEAD
ref: refs/heads/master

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementAn improvement of existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions