Gitlab push. You are not allowed to access master
I had this problem because I had master
as a protected branch
Once I unprotected the branch I was able to push fine
Fix GitLab error: you are not allowed to push code to protected branches on this project?
there's no problem - everything works as expected.
In GitLab some branches can be protected. By default only Maintainer/Owner users can commit to protected branches (see permissions docs). master
branch is protected by default - it forces developers to issue merge requests to be validated by project maintainers before integrating them into main code.
You can turn on and off protection on selected branches in Project Settings (where exactly depends on GitLab version - see instructions below).
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
(rebase etc.)
Since GitLab 9.3
Go to project: "Settings" → "Repository" → "Expand" on "Protected branches"
I'm not really sure when this change was introduced, screenshots are from 10.3 version.
Now you can select who is allowed to merge or push into selected branches (for example: you can turn off pushes to master
at all, forcing all changes to branch to be made via Merge Requests). Or you can click "Unprotect" to completely remove protection from branch.
Since GitLab 9.0
Similarly to GitLab 9.3, but no need to click "Expand" - everything is already expanded:
Go to project: "Settings" → "Repository" → scroll down to "Protected branches".
Pre GitLab 9.0
Project: "Settings" → "Protected branches" (if you are at least 'Master' of given project).
Then click on "Unprotect" or "Developers can push":
remote: GitLab: You are not allowed to push code to protected branches on this project
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.
Getting permission denied (public key) on gitlab
I found this after searching a lot. It will work perfectly fine for me.
- Go to "Git Bash" just like cmd. Right click and "Run as Administrator".
- Type
ssh-keygen
- Press enter.
- It will ask you to save the key to the specific directory.
- Press enter. It will prompt you to type password or enter without password.
- The public key will be created to the specific directory.
- Now go to the directory and open
.ssh
folder. - You'll see a file
id_rsa.pub
. Open it on notepad. Copy all text from it. - Go to https://gitlab.com/-/profile/keys or
- Paste here in the "key" textfield.
- Now click on the "Title" below. It will automatically get filled.
- Then click "Add key".
Now give it a shot and it will work for sure.
Git push -f is being rejected for unprotected branches
Unless the logs include any clue, you need to check the configuration in the remote repository on your on-premise GitLab server, in the folder referenced by your repository storage (for instance /home/git/repositories/...
).
cd /home/git/repositories/<namespace>/<myRepo.git>
git config -l
# with a recent enough Git
git config -l --show-scope --show-origin
Check if you have any settings which might prevent the push, like receive.denyNonFastforwards
.
git config --show-scope --show-origin receive.denyNonFastforwards
The OP confirms in the comments
First, I had to understand that all project paths were hashed and can be found under
/var/opt/gitlab/git-data/repositories/@hashed
.
The hashes are in the UI admin area under the corresponding project.Using the hashed path, I found the config file with
denyNonFastforwards
.
I changed that usinggit config --file config receive.denynonfastforwards false
.However, this changed the owner to root, and no pushes worked at all.
So I had to change back owner to git by usingchown git: config
. After that, everything worked as expected.
Related Topics
Format and Filter File to CSV Table
Reading Microphone Data by Polling Using Alsa [Or V4L2]
What's The Relation Between 32/64-Bit Application, Os and Processor
Accessing Any Memory Locations Under Linux 2.6.X
How to Use Named Mutex at Linux
How Does Apparmor Handle Linux-Kernel Mount Namespaces
Multi-Architectural Binary Rpm and The Noarch
How to Cross-Compile a Autotools Project for Arm
Git Status Between Windows and Linux Does Not Agree
Command and Script to Re-Read a File in Gnuplot
Redirecting Output of a C Program to Another C Program with a Bash Script Under Linux
Is There Any Way for Ioctl() in Linux to Specify Submission Queue Id for a Nvme Io Request
Sorting in Fortran, Undefined Reference to Qsort_