Default branch is random after git push --mirror (when no main branch exists) #7059

Open
opened 2025-11-02 07:14:39 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @malkam03 on GitHub (Mar 24, 2021).

Taking into consideration @zeripath comment on #3913.

I believe this is fixed now. Please reopen if this is still a problem.
Originally posted by @zeripath in https://github.com/go-gitea/gitea/issues/3913#issuecomment-646294904

The same behavior observed on issue #3913 is happening when there's no main branch or if the default branch is other than the main branch (for example dev).

Discovered by @jmorauga, @KimberlyOlivas and @djherrer.

Originally created by @malkam03 on GitHub (Mar 24, 2021). Taking into consideration @zeripath comment on #3913. > I believe this is fixed now. Please reopen if this is still a problem. _Originally posted by @zeripath in https://github.com/go-gitea/gitea/issues/3913#issuecomment-646294904_ The same behavior observed on issue #3913 is happening when there's no `main` branch or if the default branch is other than the `main` branch (for example `dev`). Discovered by @jmorauga, @KimberlyOlivas and @djherrer.
GiteaMirror added the type/bug label 2025-11-02 07:14:39 -06:00
Author
Owner

@a1012112796 commented on GitHub (Mar 24, 2021):

I think it's better to add a push option like -o repo.default-branch = xxxx to set default branch manually.

@a1012112796 commented on GitHub (Mar 24, 2021): I think it's better to add a [push option](https://docs.gitea.io/en-us/push-options/) like ``-o repo.default-branch = xxxx`` to set default branch manually.
Author
Owner

@lunny commented on GitHub (Mar 24, 2021):

What's the expected ?

@lunny commented on GitHub (Mar 24, 2021): What's the expected ?
Author
Owner

@malkam03 commented on GitHub (Mar 26, 2021):

What's the expected ?

That the default branch is kept the same.

@malkam03 commented on GitHub (Mar 26, 2021): > What's the expected ? That the default branch is kept the same.
Author
Owner

@marc-hb commented on GitHub (Mar 29, 2021):

BTW if you don't want to hardcode scripts to any branch name you can get the default branch with git ls-remote --quiet --symref upstream HEAD

@marc-hb commented on GitHub (Mar 29, 2021): BTW if you don't want to hardcode scripts to any branch name you can get the default branch with `git ls-remote --quiet --symref upstream HEAD`
Author
Owner

@lunny commented on GitHub (Mar 31, 2021):

I don't know if the sequence of branches is fixed when git push --mirror from git. If that, the first branch should be the default branch of Gitea.

@lunny commented on GitHub (Mar 31, 2021): I don't know if the sequence of branches is fixed when `git push --mirror` from git. If that, the first branch should be the default branch of Gitea.
Author
Owner

@djherrer commented on GitHub (Mar 31, 2021):

Hi, maybe an Idea is, add a aditional row on repo.json per gitlab like:

"defaultMainRepo": "yourDefaultMainBranch"

and then when execute the migration add -o repo.default-branch = xxxx ( concatenate the defaultMainRepo value in this section), and if this json value is null, run as main branch.

I think could be more userful the user put in there what are their custom main branch temporally and in the future maybe create a main branch detector similar of the next line:
git ls-remote --symref https://gitlab.com/Repo HEAD | awk '/^ref:/ {sub(/refs/heads//, "", $2); print $2}'

@djherrer commented on GitHub (Mar 31, 2021): Hi, maybe an Idea is, add a aditional row on repo.json per gitlab like: "defaultMainRepo": "yourDefaultMainBranch" and then when execute the migration add **-o repo.default-branch = xxxx** ( concatenate the defaultMainRepo value in this section), and if this json value is null, run as main branch. I think could be more userful the user put in there what are their custom main branch temporally and in the future maybe create a main branch detector similar of the next line: **git ls-remote --symref https://gitlab.com/Repo HEAD | awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}'**
Author
Owner

@yp05327 commented on GitHub (Apr 9, 2024):

Tested in the latest version, the default branch will always be the correct one.
So it seems that this issue has been fixed, as there has been a long time from the first report, it is hard to figure out which PR(s) fixed this issue.

If someone can confirm whether it is really fixed, then we can closed this issue.

@yp05327 commented on GitHub (Apr 9, 2024): Tested in the latest version, the default branch will always be the correct one. So it seems that this issue has been fixed, as there has been a long time from the first report, it is hard to figure out which PR(s) fixed this issue. If someone can confirm whether it is really fixed, then we can closed this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#7059