Gitlab: You Are Not Allowed to Access Master! After Moving Gitlab to Another Server

Gitlab push. You are not allowed to access master

I had this problem because I had master as a protected branch

Protect branch won't accept push

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"

Sample Image

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".

Sample Image

Pre GitLab 9.0

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

Settings → Protected branches

Then click on "Unprotect" or "Developers can push":

Sample Image

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.

  1. Go to "Git Bash" just like cmd. Right click and "Run as Administrator".
  2. Type ssh-keygen
  3. Press enter.
  4. It will ask you to save the key to the specific directory.
  5. Press enter. It will prompt you to type password or enter without password.
  6. The public key will be created to the specific directory.
  7. Now go to the directory and open .ssh folder.
  8. You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it.
  9. Go to https://gitlab.com/-/profile/keys or
  10. Paste here in the "key" textfield.
  11. Now click on the "Title" below. It will automatically get filled.
  12. 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 using git 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 using chown git: config. After that, everything worked as expected.



Related Topics



Leave a reply



Submit