Merging a Merge request from command line in GitLab

Viewed 9120

I'm trying to find a way to merge a merge request in GitLab from the command line.

Does anyone know how this can be achieved instead of merging the same from the GUI interface.

Any pointers are greatly appreciated. Thanks!

3 Answers

You can merge it like any other branch:

git checkout target-branch
git merge feature-branch
git push

The Gitlab UI will then show the merge request as merged.

Need to use git CLI version 2.10+. Source: First time GitLab & CI/CD workshop with Michael Friedrich @ 1:01:20

Quick test example, slightly modified from the above video.

# create a small test branch
git checkout master
git pull
git checkout -b "Testing_Create_MR_from_git_cmdline"
echo "Please delete this file" > BogusPleaseDelete.txt
git add -A
git commit -m "Testing create MR from Git command line"

# Create Gitlab MR from Git CLI
git push -u origin HEAD \
  -o merge_request.create \
  -o merge_request.title="DRAFT: $(git branch --show-current)" \
  -o merge_request.description="This MR is created by git command line, using $(git version), OS = $(lsb_release -d)" \
  -o merge_request.target=master \
  -o merge_request.remove_source_branch \
  -o merge_request.squash
Related