Skip to content

the user with Developer permissions is unable to push existing local git repository to the empty Gitlab project

Summary

On Gitlab 14.3.3 (self-managed) the user with Developer permissions is unable to push existing local git repository to the empty Gitlab project (without any branches).

Steps to reproduce

  • create new project with API (the result is the Gitlab project without branches)
  • under a user with Developer permissions for this project, try to push an existing local git repository to the created one with:
git remote rename origin old-origin
git remote add origin https://<gitlab-self-managed-host/created-repo-reference>.git
git push -u origin --all

What is the current bug behavior?

Push has failed. Output:

remote: GitLab:
remote: A default branch (e.g. main) does not yet exist for <repo-path>
remote: Ask a project Owner or Maintainer to create a default branch:
...
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to <repo-url>

The push becomes possible only after creation of ANY (not only the 'main') branch by the privileged user.

What is the expected correct behavior?

In earlier versions (we are using 14.1.5 currently), the user with Developer access was able to push an existing local git repository to the empty Gitlab project, with all refs. After the first push, the default branch was declared protected, and further push to the default/protected branch was blocked, which seems to be the correct behavior.

Possible fixes