Skip to content
LatchkeyLatchkey home

glab mr create: Open GitLab Merge Requests in CI

glab mr create opens a merge request; --fill and --yes make it fully non-interactive for pipelines.

Automating merge requests (release bumps, dependency updates) needs mr create to run without prompts. The --fill and --yes flags supply the title/description and skip confirmations.

What it does

glab mr create opens a merge request from the current or a named source branch into a target branch. Without flags it prompts; --fill derives the title and body from commits, and --yes skips the final confirmation.

Common usage

Terminal
# fully non-interactive from commit messages
glab mr create --fill --yes \
  --source-branch "$CI_COMMIT_REF_NAME" --target-branch main
# explicit title, label, and auto-merge when pipeline passes
glab mr create --title "Bump deps" --description "automated" \
  --label dependencies --remove-source-branch --yes

Options

FlagWhat it does
--fillDerive title and description from commit messages
--source-branch <b>Branch to merge from
--target-branch <b>Branch to merge into (default the repo default branch)
--yes / -ySkip the confirmation prompt
--label <name>Add a label (repeatable)
--remove-source-branchDelete the source branch after merge
--draftOpen as a draft merge request

In CI

Always pass --fill (or explicit --title/--description) plus --yes; without them glab drops into interactive editors and hangs the job. The token needs api scope; CI_JOB_TOKEN cannot create MRs, so use a project or group access token exported as GITLAB_TOKEN.

Common errors in CI

"authentication required" means GITLAB_TOKEN is missing or wrong scope. "the request returned error 409: {message: ...} branch ... already has an open merge request" means an MR already exists for that branch. "GraphQL: ... insufficient_scope" or "403 Forbidden" means the token lacks api scope. A silent hang means you omitted --yes and glab is waiting on stdin.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

glab mr create: Open GitLab Merge Requests in CI?
Automating merge requests (release bumps, dependency updates) needs mr create to run without prompts. The --fill and --yes flags supply the title/description and skip confirmations.
What it does?
glab mr create opens a merge request from the current or a named source branch into a target branch. Without flags it prompts; --fill derives the title and body from commits, and --yes skips the final confirmation.
In CI?
Always pass --fill (or explicit --title/--description) plus --yes; without them glab drops into interactive editors and hangs the job. The token needs api scope; CI_JOB_TOKEN cannot create MRs, so use a project or group access token exported as GITLAB_TOKEN.
Common errors in CI?
"authentication required" means GITLAB_TOKEN is missing or wrong scope. "the request returned error 409: {message: ...} branch ... already has an open merge request" means an MR already exists for that branch. "GraphQL: ... insufficient_scope" or "403 Forbidden" means the token lacks api scope.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card