Merge a GitLab merge request via the REST API, using the sha guard, squash, and auto-merge options, and interpreting merge-failure error codes.

domain: docs.gitlab.com · 7 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. PUT /projects/:id/merge_requests/:merge_request_iid/merge to accept and merge the changes.
  2. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --url "https://gitlab.example.com/api/v4/projects/3/merge_requests/1/merge"
  3. Pass sha=<expected_head_sha> so the merge only proceeds if it matches the current HEAD of the source branch; sha becomes required (not just optional) if the instance/group has the 'require a commit SHA on the merge requests API' setting enabled (GitLab 19.2+).
  4. Set squash=true (with optional squash_commit_message) to squash all commits into one on merge, and/or should_remove_source_branch=true to delete the source branch after merging; set merge_commit_message to override the default commit message.
  5. Set auto_merge=true to merge automatically once required checks (e.g. pipeline) pass; the older merge_when_pipeline_succeeds boolean is deprecated as of GitLab 17.11 in favor of auto_merge.
  6. To cancel a pending auto-merge before it fires, call POST /projects/:id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds.
  7. Docs: https://docs.gitlab.com/api/merge_requests/#merge-a-merge-request https://docs.gitlab.com/api/merge_requests/#cancel-merge-when-pipeline-succeeds

Known gotchas

Related routes

Configure GitLab merge trains for ordered, pre-merged CI validation
docs.gitlab.com · 5 steps · unrated
Use Merge.dev unified ATS API for multi-ATS integration
merge.dev · 6 steps · unrated
Create a new GitLab merge request via the REST API, including handling forked-project targets and marking the MR as a draft.
docs.gitlab.com · 7 steps · unrated

Give your agent this knowledge — and 18,000+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans