6

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!

4
  • 1
    Checkout merge requests locally as branches and merge them. Commented Nov 9, 2018 at 9:52
  • Interesting workaround, but does that mean the new push of the local branch after the merge request is checked out would create a new remote branch and merge it rather than the original merge request? I'm looking to simply merge the original merge request present on gitlab. Commented Nov 9, 2018 at 20:12
  • 1
    Then you need to use an API command line wrapper like git-spindel, gitlab, gitlab-cli, cli-gitlab. Commented Nov 9, 2018 at 20:21
  • Thanks phd, That's exactly what I was trying to avoid, installing something additional, this question was to find if there was a way to do it without any additions and if there was an existing gitlab ABI that could be used to perform this. Commented Nov 9, 2018 at 21:32

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the info oxley, I was looking for something like a command to merge the merge commit with the merge commit number or the SHA number as we can do in git. gerrit review $COMMIT_ID --message '"Submit changes to GIT."' --submit
This doesn't work if the branch you're trying to merge in is protected. Even if you're allowed to merge the MR from the UI (hence clicking the "Merge" button would do exactly the same thing).
3

The GitLab API allows us to do this:

https://docs.gitlab.com/ee/api/merge_requests.html#merge-a-merge-request

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.