Skip to content

Able to push to /ref/merge-requests/*/head

Description of the problem

TL;DR: You are able to push to /ref/merge-requests/*/head but it doesn't update the merge request and unable to delete it or rewrite history.

As per the docs, I added fetch = +refs/merge-requests/*/head:refs/remotes/origin/mr/* to the upstream remote in my git config in order to be able to checkout merge requests locally.

I checkout out merge request swanbarton/tech/rttp!49 locally to mr/49. I added a few commits to the local branch mr/49 and tried to push them up. I got the following error:

$ git push upstream
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push upstream HEAD:refs/remotes/upstream/mr/49

To push to the branch of the same name on the remote, use

    git push upstream HEAD

To choose either option permanently, see push.default in 'git help config'.

So I did a git push upstream HEAD:refs/remotes/upstream/mr/49. I could see that upstream/mr/49 had been updated but when refreshing the merge request in GitLab.com the new commits weren't shown. I thought this might just be a UI glitch as I could see upstream/mr/49 had updated so I went ahead and merged the merge request.

As you can see from the image below, this did not include the commits I had made.
image

I thought no problem I will just rebase those changes onto develop and revert upstream/mr/49 back to the Apply suggestion to Dockerfile commit. Whilst trying to push the changes to revert upstream/mr/49 I got this error:

$ git push upstream HEAD:refs/remotes/upstream/mr/49
Total 0 (delta 0), reused 0 (delta 0)
To https://gitlab.com/swanbarton/tech/rttp.git
 ! [remote rejected] HEAD -> upstream/mr/49 (deny updating a hidden ref)
error: failed to push some refs to 'https://gitlab.com/swanbarton/tech/rttp.git'

Force pushing had the same response. If I delete upstream/mr/49 it reappears in the next git fetch in the same place. I now have this branch in the wrong place and I can't seem to do anything about it. Is there a way to fix this?

Suggested changes to prevent this from happening in the future:

  • Prevent people from pushing to /ref/merge-requests/*/head so they don't end up in the irreversible state.
  • Allow people to push to (and rewrite history of) /ref/merge-requests/*/head and update the merge request when they do.

Which Group/Project (with full path) is experiencing the issue?

swanbarton/tech/rttp>

Approximate date/time when the error occurred.

2019/10/22 @ 16:00 UTC+01

EDIT 2019/10/23

I was actually able to delete the remote branch via git push upstream --delete merge-requests/49/head. The GUI program I was using wasn't doing it correctly. Note to self: always revert to CLI when testing that things don't work! So I'm able to delete the branch but not rewrite its history - seems odd.

Edited by 🤖 GitLab Bot 🤖