Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 of 7 tasks
vg-c opened this issue Jul 24, 2019 · 3 comments · Fixed by #7610
Closed
2 of 7 tasks

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

vg-c opened this issue Jul 24, 2019 · 3 comments · Fixed by #7610
Labels
type/enhancement An improvement of existing functionality

Comments

@vg-c
Copy link

vg-c commented Jul 24, 2019

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

@zeripath
Copy link
Contributor

zeripath commented Jul 25, 2019

This is not a fault of Gitea - but rather of Git itself.

Try the following on your local machine from a temporary directory:

git init --bare push-to.git
git init to-push
cd to-push
touch README
git add README
git commit -a -m'Add Readme'
git branch -m master newbranch
git remote add origin ../push-to.git
git push -u origin newbranch
cd ..
git clone push-to.git to-clone

Git push does not update the HEAD on push-to.git and it still points to master therefore the clone will not work.

That is not to say that we cannot add a feature, but this is not a bug.

@vg-c
Copy link
Author

vg-c commented Jul 25, 2019

At least GitHub does overcome this "bug" of Git. See e.g. https://github.com/vg-c/testdefaultbranch

It would be nice if Gitea could do the same.

@zeripath
Copy link
Contributor

hence #7610

@lunny lunny added the type/enhancement An improvement of existing functionality label Jul 29, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants