Create from template does not reference the right branch. #9912

Closed
opened 2025-11-02 08:52:57 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @saul-jb on GitHub (Nov 30, 2022).

Description

If you create a template with a different default branch (e.g. not 'main') and create another repository from that template, it sets the default branch to an empty reference to 'main' causing this error when cloning it warning: remote HEAD refers to nonexistent ref, unable to checkout.. This can be resolved by changing the default branch to the one from the template but that should be the default behavior or at least it should provide an option to specify the name of the branch.

To reproduce:

  1. Create a template repository with the default branch as anything but 'main'.
  2. Create a repository from that template including the git content of the template.
  3. Check to see if the default branch points to an invalid ref.

Gitea Version

1.18.0

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Problem exists on both https://try.gitea.io/ and docker.

Database

No response

Originally created by @saul-jb on GitHub (Nov 30, 2022). ### Description If you create a template with a different default branch (e.g. not 'main') and create another repository from that template, it sets the default branch to an empty reference to 'main' causing this error when cloning it `warning: remote HEAD refers to nonexistent ref, unable to checkout.`. This can be resolved by changing the default branch to the one from the template but that should be the default behavior or at least it should provide an option to specify the name of the branch. To reproduce: 1. Create a template repository with the default branch as anything but 'main'. 2. Create a repository from that template including the git content of the template. 3. Check to see if the default branch points to an invalid ref. ### Gitea Version 1.18.0 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? Problem exists on both https://try.gitea.io/ and docker. ### Database _No response_
GiteaMirror added the issue/confirmedtype/bug labels 2025-11-02 08:52:57 -06:00
Author
Owner

@wolfogre commented on GitHub (Jan 19, 2023):

I cannot reproduce it on v1.18.0.

Are you sure that you found it on v1.18.0? The release time is after the time you opened this issue.

You can find the exact version in the footer of any page.

@wolfogre commented on GitHub (Jan 19, 2023): I cannot reproduce it on v1.18.0. Are you sure that you found it on v1.18.0? The [release time](https://github.com/go-gitea/gitea/releases/tag/v1.18.0) is after the time you opened this issue. You can find the exact version in the footer of any page.
Author
Owner

@saul-jb commented on GitHub (Jan 19, 2023):

I cannot reproduce it on v1.18.0.

Are you sure that you found it on v1.18.0? The release time is after the time you opened this issue.

You can find the exact version in the footer of any page.

Just checked and the issue still remains, version is: 1.18.0+rc0 and I also checked it remains on try.gitea.io version 1.19.0+dev-331-gb383652e0: https://try.gitea.io/saul/repo-2-from-template/src/branch/master.

@saul-jb commented on GitHub (Jan 19, 2023): > I cannot reproduce it on v1.18.0. > > Are you sure that you found it on v1.18.0? The [release time](https://github.com/go-gitea/gitea/releases/tag/v1.18.0) is after the time you opened this issue. > > You can find the exact version in the footer of any page. Just checked and the issue still remains, version is: `1.18.0+rc0` and I also checked it remains on try.gitea.io version `1.19.0+dev-331-gb383652e0`: https://try.gitea.io/saul/repo-2-from-template/src/branch/master.
Author
Owner

@wolfogre commented on GitHub (Jan 29, 2023):

Just checked and the issue still remains, version is: 1.18.0+rc0 and I also checked it remains on try.gitea.io version 1.19.0+dev-331-gb383652e0: try.gitea.io/saul/repo-2-from-template/src/branch/master.

Sorry, could you please point it out where's the problem? I don't see anything special in the example repo you give:

image

And I also created a repo from your template, but I didn't see any warning when browsing or cloning it.

@wolfogre commented on GitHub (Jan 29, 2023): > Just checked and the issue still remains, version is: `1.18.0+rc0` and I also checked it remains on try.gitea.io version `1.19.0+dev-331-gb383652e0`: [try.gitea.io/saul/repo-2-from-template/src/branch/master](https://try.gitea.io/saul/repo-2-from-template/src/branch/master). Sorry, could you please point it out where's the problem? I don't see anything special in the example repo you give: <img width="1177" alt="image" src="https://user-images.githubusercontent.com/9418365/215313936-b34842e2-a0fc-44bc-84b6-bc1c86f385bb.png"> And I also created a [repo](https://try.gitea.io/wolfogre/test_template) from your template, but I didn't see any warning when browsing or cloning it.
Author
Owner

@saul-jb commented on GitHub (Jan 29, 2023):

Your repo seems to have the same problem.

Sorry, could you please point it out where's the problem? I don't see anything special in the example repo you give:

> git clone https://try.gitea.io/saul/repo-2-from-template.git
Cloning into 'repo-2-from-template'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

It is that last line that is warning that the HEAD refers to a non-existent ref.

When I try to pull changes, the problem becomes more obvious:

> git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master


Git again complains here because we are not on a branch that exists on the origin. The UI also reflects this:

image

See how the selection shows main but is greyed out since it does not exist and you need to manually change it to master (or any other branch that actually exists).

If you leave the template's default branch as main this issue does not occur. It seems to me that the main branch is hard-coded somewhere when creating a repository from a template rather than using the default branch from the template.

@saul-jb commented on GitHub (Jan 29, 2023): Your repo seems to have the same problem. > Sorry, could you please point it out where's the problem? I don't see anything special in the example repo you give: ``` > git clone https://try.gitea.io/saul/repo-2-from-template.git Cloning into 'repo-2-from-template'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done. warning: remote HEAD refers to nonexistent ref, unable to checkout. ``` It is that last line that is warning that the HEAD refers to a non-existent ref. When I try to pull changes, the problem becomes more obvious: ``` > git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master ``` Git again complains here because we are not on a branch that exists on the origin. The UI also reflects this: ![image](https://user-images.githubusercontent.com/2025187/215317046-6bc2b12e-ecce-4582-87a2-bc78a15d6447.png) See how the selection shows `main` but is greyed out since it does not exist and you need to manually change it to `master` (or any other branch that actually exists). If you leave the template's default branch as `main` this issue does not occur. It seems to me that the `main` branch is hard-coded somewhere when creating a repository from a template rather than using the default branch from the template.
Author
Owner

@wolfogre commented on GitHub (Feb 1, 2023):

Duplicated with #19470.

@wolfogre commented on GitHub (Feb 1, 2023): Duplicated with #19470.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#9912