LinuxCommandLibrary

glab-mr-merge

Merge GitLab merge requests

TLDR

Merge the merge request associated with the current branch interactively

$ glab mr merge
copy

Merge the specified merge request, interactively
$ glab mr merge [mr_number]
copy

Merge the merge request, removing the branch on both the local and the remote
$ glab mr merge [[-d|--remove-source-branch]]
copy

Squash the current merge request into one commit with the message body and merge
$ glab mr merge [[-s|--squash]] [[-m|--message]] "[commit_message_body]"
copy

Display help
$ glab mr merge --help
copy

SYNOPSIS

glab mr merge [<id|branch>] [flags]

PARAMETERS

-d, --delete-source-branch
    Delete source branch after successful merge.
Alias: -D, --remove-source-branch (deprecated).

-l, --label <name[,name...]>
    Add labels to the merge request.

-m, --message, --merge-commit-msg <message>
    Set custom merge commit message.

-R, --repo <repo>
    Repository context; defaults to current ($GLAB_REPO).

-s, --source-branch <branch>
    Override source branch; inferred from arg or current.

-S, --squash-before-merge
    Squash all source branch commits before merging.

-t, --target-branch <branch>
    Override target branch.

--milestone <milestone>
    Add milestone to MR.

--reviewer <users>
    Request review from users (id or username).

--update-assignee
    Add current user to assignees.

DESCRIPTION

The glab mr merge command merges a GitLab merge request (MR) from the terminal, streamlining workflows for developers and CI/CD pipelines.

It accepts an MR ID (like 42) or source branch name as the primary argument. Without arguments, it infers the current branch's MR.

Key features include custom merge messages, labeling, milestone assignment, source branch deletion post-merge, and squashing commits into one before merging. Reviewers can be requested, and assignees updated automatically.

Usage requires prior authentication with glab auth login and appropriate project permissions (e.g., Developer role or higher). The command verifies mergeability, handling fast-forward, semi-linear, or merge strategies based on project settings.

Ideal for scripting merges in automation or quick terminal operations. On success, it updates the MR status, potentially triggering pipelines. Errors occur for unmergeable MRs due to conflicts, approvals, or branch protection rules.

(187 words)

CAVEATS

Fails if MR unmergeable (conflicts, unapproved, protected branches). Requires push access to target. Interactive editor opens for message unless --no-edit. Always run glab mr merge --help for latest flags.

EXAMPLES

glab mr merge 42 -d -S -m "Merge feat X"
Merges MR 42, deletes source branch, squashes, custom message.

glab mr merge -l bug,needs-qa
Merges current branch MR, adds labels.

EXIT CODES

0: success.
1: error (unmergeable, auth fail, network).

HISTORY

Introduced in glab v1.0 (2020) by GitLab Inc. as part of open-source CLI suite. Evolved with GitLab API; squash/delete options added in v1.5+. Actively maintained on GitHub.

SEE ALSO

glab mr(1), glab mr approve(1), glab mr view(1), git merge(1)

Copied to clipboard