How to auto create MRs in Gitlab

In this article, we will go over how we can use the gitlab-auto-mr CLI script I wrote to help automate your Gitlab workflow. This is a very simple script you can use with Gitlab which will auto-create merge requests (MRs) every time you create a new branch on a project in Gitlab.

(Optional) Git Feature Branches

Gitlab Workflow
Gitlab Workflow

CI/CD

Gitlab Auto MR

I created a simple CLI script, that I run during on Gitlab CI, which will auto-create merge requests every time you create a new branch. So you could have something like this:

stages:
- pre

create:merge-request:
image: registry.gitlab.com/gitlab-automation-toolkit/gitlab-auto-mr
stage: pre
except:
- master
- tags
script:
- gitlab_auto_mr -t master -c WIP -d .gitlab/merge_request_templates/merge_request.md -r -s --use-issue-name
# Description

<!-- please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->

## Type

- [ ] Bug Fix
- [ ] Improvement
- [ ] New Feature

Fixes #<!-- Issue Number -->
  • -s: Will squash our commits into a single commit, so each feature branch will appear as a single commit onto the master branch
  • --use-issue-name: If set and you do something like feature/#6 it will search for the issue with id 6 and pull information from there like labels and milestones etc. It will then assign those to this MR, an example of this can be seen with MR here where the issue #211 is here

Appendix

Software Engineer | Pythonista | Typescripter | Docker Advocate | https://haseebmajid.dev