I am trying to push to master branch of a repo and I am failing to do so, since it is protected.
I tried to look into the project settings and do not see any option for protected branches. The only option I could see is members.
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 repo has only one branch, with no contents in it so far.
I do see protected branches options of my other Repos but not for this specific one.
It is a new repo with no contents and with only default branch.
I have the master
permission.
Unfortunately I am not able to upload the image here somehow.
Please suggest how to push code to master branch.
with no contents in it so far
That means there is no master
branch to protect yet, because the empty repo does not has one.
To "Enable/disable branch protection", you need to be Master or Owner of the GitLab project (which you are).
Make sure:
- your first push is a
git push -u origin master
;
- the remote
origin
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.
It means that you may have a master
branch, but it is protected in project settings. See:
how to fix: you are not allowed to push code to protected branches on this project or https://gitlab.com/gitlab-com/support-forum/issues/207.
In order to access project settings and unprotect the branch, you need to have sufficient rights.
12/17/2018
1. git push
: "error: failed to push some refs to"
git push -f
: "remote rejected"
2. the branch is in a protected state and cannot be forced to operate.
Gitlab - Repository - Branches
3. temporarily remove branch protection.
Gitlab - Settings - Repository - Protected Branches - Unprotect
4. try pushing again
git push -f
5. may add protection
Project: "Settings" -> "Protected branches" (if you are at least 'Master' of given project).
Then click on "Unprotect" or "Developers can push"
In GitLab some branches can be protected. By default only 'master' user can commit to protected branches and master branch is protected by default.
You can turn on and off protection on selected branches in Project Settings (Go to project: "Settings" -> "Repository" -> "Expand" on "Protected branches" ).
On the same settings page you can also allow developers to push into the protected branches. With this setting on, protection will be limited to rejecting operations requiring git push --force
Perhaps the master branch opens the protection. You need to select the developer to push in the protection branch settings.