How to use push -o merge_request.create

I think I misunderstand how to use merge_request.create, since it just wont work…

I want to disable direct push to a branch, and instead get a merge request to review. I set “none” to Allowed to push, and allowed to merge to the user I tested with. Using git client version 2.17.1, that should have support for -o option.

When I try git push -o merge_request.create I get:

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

What am I missing? If I enable push to the user, the -o option is simply ignored and the code gets pushed without creating a merge request.

In your local repo are you in the protected branch, or branch off of it?

The way I’ve used the push option is:

  1. make a feature branch off of the branch I plan to merge into (“master” is my protected branch in this example)
  2. make commits to feature branch
  3. git push -o merge_request.create -o merge_request.target=master

The -o merge_request.target bit may not be necessary, though I’m not sure how it determines the target for the MR otherwise.

The -o merge_request.target bit may not be necessary, though I’m not sure how it determines the target for the MR otherwise.
Default target if this option is not passed is the “Default branch” defined in the project.

1 Like