Git push with merge_request.create

I am having trouble pushing with a merge_request.create into a protected branch.

It is probably something obvious what I am doing wrong, but unfortunately, I cannot find much help with similar issues online.

I see this issue when:

  • I started by cloning the repository into a local machine, and creating a separate local branch (updated_prd) from the master branch.

  • After making a few changes and doing the associated commits I tried to push them to the remote:
    > git push -o merge_request.create -o origin updated_prd:master

    Getting the error:
    fatal: The current branch updated_prd has no upstream branch.

  • To chose the upstream branch I then did:
    > git branch -u origin/master

    Which appeared to work:
    Branch 'updated_prd' set up to track remote branch 'master' from 'origin'.

  • Finally, I retried the push:
    > git push -o merge_request.create origin updated_prd:master

    This time getting the error associated with the protected branch:
    Enumerating objects: 136, done.

    remote: GitLab: You are not allowed to push code to protected branches on this project.
    ! [remote rejected] updated_prd -> master (pre-receive hook declined) error: failed to push some refs to ...

Can anyone identify what I am doing wrong? Does the new temporary branch also need to exist on the remote?

Ok, after multiple retries, I managed to succeed.

Apparently, there was something not appropriate with the way I was creating the local branch (For that part, I was using a GUI interface instead of doing a git checkout -b from the shell).

Following these commands I managed to originate the merge request right from the git push command. The last step that is missing from the guide, was:

> git push -o merge_request.create -o origin updated_prd

For posterity, I will leave this up with the fix.

If I followed your timeline of events correctly it seems like a very simple GitLab repo permission setting. Have you checked to make sure your role has the appropriate permission to merge into a protected branch?