rohit tamang
rohit tamang

Reputation: 91

You are not allowed to push code to protected branches on this project.?

when i push my code to the gitlab ,it gives this kind of error because i am new to the git. please guide me !

$ git push origin master                                                                                                Counting objects: 71, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (54/54), done.
Writing objects: 100% (71/71), 9.93 KiB | 0 bytes/s, done.
Total 71 (delta 23), reused 0 (delta 0)
remote: GitLab: You are not allowed to push code to protected branches on this project.To https://gitlab.com/akash/demo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/akash/demo.git'

Upvotes: 1

Views: 13326

Answers (2)

ElpieKay
ElpieKay

Reputation: 30868

A protected branch prevents some or all of the roles, like Developer, Maintainer, and Owner, from direct push.

If you want direct push, you have 3 options:

  1. Ask the repository owner to unprotect the branch.
  2. Ask the repository owner to put your username in the role that is allowed to push.
  3. Raise a merge request (or a pull request or a whatever-name thing depending on the hosting service) whenever you want to push to the protected branch.

In most cases, the 3rd one is the expected solution. A merge request makes it possible that your commits are reviewed before being merged to the target branch. A protected branch minimizes the chance of receiving unqualified changes and prevents the branch from being deleted mistakenly or maliciously.

Upvotes: 3

TS_
TS_

Reputation: 317

Protected branch is just what it sounds like. Seems like you are not the owner of the branch 'cause the owner chose to make it impossible for you to push changes into the branch, and honestly - you have nothing to do about it.

If you are the owner and somehow it happened, it can be easily fixed by clicking the Unprotect button next to master branch, in the repository.

Upvotes: 1

Related Questions