glab-mr-merge
Merge GitLab merge requests
TLDR
Merge the merge request associated with the current branch interactively
Merge the specified merge request, interactively
Merge the merge request, removing the branch on both the local and the remote
Squash the current merge request into one commit with the message body and merge
Display help
SYNOPSIS
glab mr merge <MR_ID | branch> [flags]
PARAMETERS
--branch <string>
Specify the target branch for the merge operation.
--delete-source-branch, -d
Delete the source branch after a successful merge.
--force, -f
Force merge, bypassing pipeline status, conflicts, or other restrictions. Use with caution.
--message <string>, -m <string>
Provide a custom message for the merge commit.
--pipeline-succeeds
Set the merge request to merge automatically once all CI/CD pipelines successfully complete.
--rebase, -r
Rebase the source branch onto the target branch before merging.
--squash, -s
Squash all commits from the source branch into a single commit upon merge.
--squash-message <string>, -t <string>
Provide a custom message for the squashed commit.
--title <string>
Provide a custom title for the merge commit.
--wait, -w
Wait for the merge operation to complete before exiting the command.
DESCRIPTION
The glab mr merge command is a core subcommand of the glab (GitLab CLI) tool, designed to streamline the process of merging GitLab Merge Requests (MRs) directly from your terminal. It allows developers to quickly complete a merge request without navigating to the GitLab web interface.
This command supports various options to control the merge behavior, such as rebasing before merging (--rebase), squashing commits (--squash), deleting the source branch after a successful merge (--delete-source-branch), and setting a custom merge commit message (--message). It also supports the "merge when pipeline succeeds" feature (--pipeline-succeeds), which is crucial for CI/CD workflows, ensuring code quality before integration. The command typically requires the MR ID or an alias (like the current branch name if it's an MR branch) as an argument.
CAVEATS
The command requires appropriate permissions on the GitLab project to merge an MR.
The Merge Request must be in a mergeable state (e.g., no unaddressed discussions, no conflicts, unless --force is used).
Conflicts must typically be resolved manually through the GitLab UI or by rebasing/merging locally before attempting to merge via glab.
Using --force can bypass important pre-merge checks, so it should be used judiciously.
MERGE REQUEST ID / ALIAS
The <MR_ID | branch> argument can be the numeric ID of the merge request (e.g., 123), a full GitLab MR URL, or a reference like !123. If omitted, glab attempts to infer the MR from the current Git branch you are on, assuming it's a feature branch associated with an open MR.
PRE-MERGE CHECKS
glab mr merge respects GitLab's project settings, including required approvals, successful CI/CD pipelines, and conflict status. The --force flag can override some of these checks, but should be used with extreme caution to avoid introducing issues into the codebase.
HISTORY
glab was introduced in late 2020 as the official GitLab CLI tool, aiming to bring GitLab functionalities to the command line, similar to GitHub's gh CLI. The mr (merge request) functionalities, including the merge subcommand, have been foundational components since its early versions, evolving to align with new features and best practices in GitLab.
SEE ALSO
glab mr create, glab mr list, glab mr checkout, glab mr approve, git merge(1), git rebase(1)