Unable to push files to git due to: failed to push some refs

Viewed 72515

I have a directory that i want to turn into a git project.

I created a new project in gitlab and then i did the following:

git init
git remote add origin git@gitlab.com:a/b/c.git
git add .
git commit -m "Initial commit"
git push -u origin master

In addition, I created the following .gitignore file:

*
!*/scripts
!*/jobs

After running git push -u origin master i got the following error:

Counting objects: 33165, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (32577/32577), done.
Writing objects: 100% (33165/33165), 359.84 MiB | 1.70 MiB/s, done.
Total 33165 (delta 21011), reused 0 (delta 0)
remote: Resolving deltas: 100% (21011/21011), done.
remote: GitLab: 
remote: A default branch (e.g. master) does not yet exist for a/b/c
remote: Ask a project Owner or Maintainer to create a default branch:
remote: 
remote:   https://gitlab.com/a/b/c/project_members
remote: 
To gitlab.com:a/b/c.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.com:a/b/c.git'

What could be the issue? Please advise

2 Answers

This is linked to issue 27456 and merge request 6608:

document the need to be owner or have the master permission level for the initial push

So it might be a permission level, not a branch issue.

See commit 81ee443:

You will need to be owner or have the master permission level for the initial push, as the master branch is automatically protected.

I had this issue for quite some time as well. Tried different things, but it did not work. The owner of the GitLab repository of my company changed my status from "Developer" to "Maintainer" and it finally worked for me.

Related