July 22, 2024 /
1 min /
#git
#automation
#ci-cd
Create merge request to target branch automatically
If you hate opening MR from the Gitlab interface after pushing the branch like I do, the following code fragment will do the trick.
git push \ -o merge_request.create \ -o merge_request.remove_source_branch \ -o merge_request.merge_when_pipeline_succeeds \ -o merge_request.target=master \ -o merge_request.assign=$(git config user.email | cut -d “@” -f 1) \ -o merge_request.title="${TITLE}”
You can then assign an alias to this script to simplify its use.
alias gpm='git_push_to_master'git_push_to_master (){ git push --no-verify \ -o merge_request.create \ -o merge_request.target=master \ -o merge_request.assign=$(git config user.email | cut -d “@” -f 1) \ -o merge_request.title="$1”}
Put the above code in ~/.zshrc
and run source ~/.zshrc
.
You can now use it as follows.
gpm “Test MR Title”