GitLab: Git alias for creating a merge request on push

Updated . Posted . Visible to the public.

Git allows you to set push options when pushing a branch to the remote.
You can use this to build an alias that automatically pushes a branch and creates a merge request for it.

Put this in your ~/.gitconfig in the [alias] section:

mr = push origin HEAD -o merge_request.create -o merge_request.draft

Now you can do git mr and a draft merge request will be created.
Target branch is your project's default branch, i.e. main or master.

To specify a different target branch, add -o merge_request.target=other-branch.

There are many more options Show archive.org snapshot that you can use to customize the created merge request.

Martin Schaflitzl
Last edit
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Martin Schaflitzl to makandra dev (2022-10-25 11:41)