Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid push --force when updating a gitlab merge request

Tags:

git

gitlab

gerrit

tl;dr How can I update a gitlab merge request the same way as a gerrit changeset?

In a rather standard gitlab setting, I own a project and want it to keep a linear history. I set the merge settings accordingly and everything works fine from the UI.

If I want to incorporate feedback into an existing merge request, I am currently forced to git push --force my branch which I find both inconvenient and dangerous. As a counterexample, gerrit has a special target refs/for/XXX where I can push my changes. Gerrit then identifies the changeset by an Id in the commit message and happily creates a new version of the changeset.

Is there a similar feature for gitlab? Can I push my (rebased, squashed, ammended) changeset somewhere so that it automatically becomes a new version of an existing MR?

like image 664
choeger Avatar asked Nov 07 '22 14:11

choeger


1 Answers

Force push is a valid workflow in this case. It is not that dangerous, because the old version of the branch is still available locally via git reflog and on the server all the versions you pushed are also saved in gitlab (see https://docs.gitlab.com/ee/user/project/merge_requests/versions.html).

You can push modifications happening during the review in new commits and once the branch is ready to be merged use gitlab's squash commits functionality if you really want to avoid force pushing, but this offers less flexibility than using interactive rebase with force push, because it means that the whole branch will be turned into a single commit before being merged.

like image 135
Étienne Avatar answered Nov 11 '22 17:11

Étienne