Mr Singh
Mr Singh

Reputation: 4230

How to make commits on protected branch in git?

My master branch in protected.

Just I want to make small(One line changes) commit on master.

I don't want to make a new branch and merge with master.

But i'm getting messages while push code on master:

remote: GitLab: You are not allowed to push code to protected branches on this project.
To https://gitlab.com/xyz/api_xyz.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/xyz/api_xyz.git'

Is it permission problem?

Can I make a commit to the protected branch?

Upvotes: 1

Views: 13088

Answers (3)

huytmb
huytmb

Reputation: 4274

From the docs: https://docs.gitlab.com/ee/user/permissions.html

Only Maintainer or Owner have "Push to protected branches" permission.

To protect a branch, you need to have at least Maintainer/Owner permission level. Note that the master branch is protected by default.

Configuring protected branches To protect a branch, you need to have at least Maintainer permission level. Note that the master branch is protected by default.

  1. Navigate to your project’s Settings ➔ Repository
  2. Scroll to find the Protected branches section.
  3. From the Branch dropdown menu, select the branch you want to protect and click Protect. In the screenshot below, we chose the develop branch.

Upvotes: 0

kowsky
kowsky

Reputation: 14549

You can commit locally, but, by default, no one (with exceptions, see link below) is allowed to push to a protected branch. You can change this default behavior in the settings; see gitlab documentation:

Since GitLab 8.11, you can define which roles are allowed to push to a protected branch via Settings->Repositories->Protected Branches: enter image description here

Alas, you should not carelessly commit and push to protected branches; they're mostly protected for a reason. Why not just create a merge request and lat your code be reviewed before it is merged?!

Upvotes: 1

MathWellan
MathWellan

Reputation: 43

In Gitlab only the project master can allow you to push in master, developpers have to issue merge request.

Go to Settings > Repository to change permissions or ask your project master to do it.

Upvotes: 0

Related Questions