Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

gitlab

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 [email protected]: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 '[email protected]:a/b/c.git'

What could be the issue? Please advise

like image 711
Omri Avatar asked Aug 26 '18 12:08

Omri


People also ask

How do I fix git failed to push some refs?

How to Fix error: failed to push some refs to Error in Git Using git pull. To send a pull request means to "fetch" new changes made to the remote repo and merge them with the local repo. Once the merging is done, you can then push your own code changes to GitHub.

Why is push not working in git?

If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.

How do I force git to push?

To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).


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.

like image 150
VonC Avatar answered Oct 19 '22 19:10

VonC


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.

like image 44
hbstha123 Avatar answered Oct 19 '22 19:10

hbstha123