Merging a Merge request from command line in GitLab
Asked Answered
L

3

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!

Leekgreen answered 9/11, 2018 at 1:2 Comment(4)
Checkout merge requests locally as branches and merge them.Thay
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.Leekgreen
Then you need to use an API command line wrapper like git-spindel, gitlab, gitlab-cli, cli-gitlab.Thay
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.Leekgreen
L
2

gitlab API allows us to do this.

https://docs.gitlab.com/ee/api/merge_requests.html#accept-mr

Leekgreen answered 14/11, 2018 at 2:51 Comment(0)
K
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.

Kayseri answered 9/11, 2018 at 6:34 Comment(2)
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."' --submitLeekgreen
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).Norther
L
2

gitlab API allows us to do this.

https://docs.gitlab.com/ee/api/merge_requests.html#accept-mr

Leekgreen answered 14/11, 2018 at 2:51 Comment(0)
M
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
Melvamelvena answered 19/7, 2021 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.