• Register
0 votes
428 views

Problem :

I want to push my code to the master branch of a repository but I am unable to do so, as it is protected.
Please find below the error message I am facing:

remote: GitLab: You are not allowed to push code to protected branches on this project.To git@gitlab.ins.risk.regn.net:cmd/release.git ! [remote rejected] master -> master (pre-receive hook declined)error: failed to push some refs to 'git@gitlab.ins.risk.regn.net:cmd/release.git'

My repository is having only one branch and there are no contents in it so far.
It is the completely new repository with no contents and only default branch.
I have all the master permissions.
Unable to upload the image here because of some reason.Kindly suggest how can I push my code to master branch.

7.5k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I have gone through your problem statement and I think your repository is with no contents in it so far

It means there is no master branch to protect currently, as the empty repository does not has one.

To do "Enable/disable branch protection", you must be Master or Owner of the GitLab project which you are.

Please make sure:

·     Your first push should be git push -u origin master;

·     Your remote origin references the right repo (git remote -v);

·     Your local ssh key should be the right one (ssh -T git@gitlab.ins.risk.regn.net);

·     You must be the member of the cmd group

38.6k points
0 votes

Solution:

In GitLab few branches can be preserved. By default just Maintainer/Owner users can promise to protected branches . master branch is preserved by default - it forces developers to issue merge requests to be affirmed by project maintainers prior integrating them into main code.

You can turn on and off protection on chosen branches in Project Settings (where nicely relies on GitLab version - view instructions below).

On the similar settings page you can also approve developers to shock into the protected branches. With this setting on, protection will be limited to refusing operations claiming git push --force (rebase etc.)

Whereas GitLab 9.3

Go to project: "Settings" → "Repository" → "Expand" on "Protected branches"

Currently, you can choose who is approved to merge or push into chosen branches (for example: you can turn off pushes to master at all, forcing all alters to branch to be made through Merge Requests). Or you can click "Unprotect" to fully remove protection from branch.

Whereas GitLab 9.0

Likewise to GitLab 9.3, however no require to click "Expand" - everything is meanwhile expanded:

Go to project: "Settings" → "Repository" → scroll down to "Protected branches".

Pre GitLab 9.0

Project: "Settings" → "Protected branches" (in case you are at least 'Master' of given project).

Whereas  GitLab Enterprise Edition 9.3.0

1-Choose you "project"

2-Choose "Repository"

3-Choose "branches"

4-Choose "Project Settings"

5-In "Protected Branches" click to "expand"

6-and after click in "unprotect" button

That imply there is no master branch to protect yet, since the empty repo does not has one.

To "Enable/disable branch protection", you require to be Master or Owner of the GitLab project .

Ensure That:

  • Your first push is a git push -u origin master;

  • The remote root does reference the right repo (git remote -v);

  • Your local ssh key is the right one (ssh -T git@gitlab.ins.risk.regn.net);

  • You are a member of the cmd group.

31.7k points
edited by