Getting started

Introduction

GitLab CLI works with merge requests, issues, and CI/CD from the terminal. This reference covers the most-used commands, JSON output, and glab api.

Install

brew install glab
winget install glab.glab
sudo snap install glab
sudo dnf install glab

Homebrew is the only officially supported package manager; the rest come from the community.

See: Installation options

Sign in

glab auth login
glab auth status
glab auth status --show-token

auth login walks through OAuth or a token and stores it in the OS keyring when one is available, falling back to the plaintext config file; --stdin reads a token from a pipe.

See: Authenticate with GitLab

Self-managed GitLab

glab auth login \
  --hostname gitlab.example.com
glab config set -g host gitlab.example.com

config set -g host makes it your default host. GITLAB_HOST overrides the host for a single command.

See: Connect to your instance

To-dos

glab todo list
glab todo list --action=assigned
glab todo list --state done
glab todo done --all

To-dos collect assignments, mentions, and failed pipelines. --action filters by reason, --state done lists cleared ones, and todo done --all clears them.

See: glab todo list

Projects

Clone

glab repo clone group/project
glab repo clone group/project mydir

A fork you own gets an upstream remote. Flags after -- go to git clone.

See: glab repo clone

Clone a group

glab repo clone -g mygroup --paginate
glab repo clone -g mygroup \
  --archived=false --paginate

--paginate clones every project in the group; --archived=false skips archived ones.

See: glab repo clone

Create

glab repo create
glab repo create my-project --private
glab repo create --group mygroup

--internal and --public set visibility; without one, the instance default applies. --skipGitInit skips git init and cloning.

See: glab repo create

Fork

glab repo fork group/project --clone
glab repo fork --remote

Without --clone or --remote, forking prompts.

See: glab repo fork

View and list

View

glab repo view
glab repo view group/project --web

List

glab repo list -m
glab repo list -g mygroup \
  --include-subgroups

-m lists projects you own; --member widens that to every project you belong to.

See: glab repo list

Archive

glab repo archive group/project
glab repo archive group/project \
  --format=tar.gz

Downloads the repository's source as a zip; --format picks another archive type.

See: glab repo archive

Prune

glab repo prune --dry-run
glab repo prune --yes

prune deletes local branches whose merge requests merged; --merged checks with Git instead of the API, but only detects fast-forward merges.

See: glab repo prune

Merge requests

Create

Interactive

glab mr create

Non-interactive

glab mr create --fill --yes
glab mr create -t "Fix login" \
  -d "Closes #42"

From an issue

glab mr create --related-issue 34
glab mr create --related-issue 34 \
  --draft

--fill takes the title and description from commits and pushes the branch; --push=false skips the push. --related-issue reuses the issue title.

See: glab mr create

List and filter

glab mr list
glab mr list --assignee=@me \
  --reviewer=@me
glab mr list --label bug --merged

--closed and --merged narrow the state; --all widens it past open requests.

See: glab mr list

Inspect and check out

View

glab mr view 123 --comments
glab mr view 123 --web

Check out

glab mr checkout 123
glab mr checkout 123 \
  --worktree ../review-123

Diff

glab mr diff 123 --raw

--worktree checks out beside your changes instead of replacing them; --raw prints a patch for git apply.

See: glab mr checkout, glab mr diff

Review

Approve

glab mr approve 123
glab mr approve 123 --sha abc123

Comment

glab mr note create 123 -m "LGTM"
glab mr note create 123 -m "Rename this" \
  --file src/app.ts --line 42

--sha refuses unless the merge request's HEAD matches; --file and --line leave a comment on the diff. The note subcommands are experimental in glab 1.130.

See: glab mr approve, glab mr note

Discussions

List

glab mr note list 123 \
  --state unresolved

Resolve

glab mr note resolve 123 abc12345

The merge request comes first, then the discussion ID or an 8-character prefix; note list shows the threads.

See: glab mr note

Merge

glab mr merge 123 --squash --yes
glab mr merge 123 --rebase
glab mr merge 123 --remove-source-branch

While a pipeline runs, merge enables auto-merge; pass --auto-merge=false to merge immediately.

See: glab mr merge

Close and reopen

glab mr close 123
glab mr reopen 123

Closing keeps the source branch; mr list --all includes closed merge requests.

See: glab mr close

Issues

Create

glab issue create \
  -t "Login fails" \
  -d "Steps to reproduce"
glab issue create -t "Bug" -l bug
glab issue create -t "Security" -c

-c marks the issue confidential; --template bug starts from .gitlab/issue_templates/; --description-file - reads the body from stdin.

See: glab issue create

List and filter

glab issue list
glab issue list -a @me -l bug
glab issue list --search "timeout" \
  --in title

@none and @any filter unassigned or assigned issues; --all includes closed ones.

See: glab issue list

Read and comment

View

glab issue view 123 --comments
glab issue view 123 --web

Comment

glab issue note 123 -m "Fixed in !456"
glab issue note 123 -m "Rotating now" \
  --internal

--internal keeps the note visible to project members only.

See: glab issue view, glab issue note

Close and reopen

glab issue close 123
glab issue reopen 123

A merge request description containing Closes #123 closes the issue on merge.

See: glab issue close

Board

glab issue board view
glab issue board create "Sprint 12"

board view is an interactive kanban board with assignee and label filters.

See: glab issue board

Pipelines

List

glab ci list
glab ci list --status=failed
glab ci list --ref main \
  --per-page 10

--source merge_request_event filters to merge request pipelines; --scope running shows active ones.

See: glab ci list

Status

glab ci status
glab ci status --live
glab ci status --wait --compact

Reports the current branch's pipeline. --live redraws until it ends; --wait returns when it does, without redrawing.

See: glab ci status

View

glab ci view
glab ci view main
glab ci view --web

In the TUI, Enter opens a job's log, Ctrl+R runs or retries, Ctrl+D cancels, and Ctrl+Q quits.

See: glab ci view

Run

glab ci run --branch main
glab ci run --mr
glab ci run --variables STAGE:staging

--variables passes CI variables, repeatable or comma-separated. --mr runs a merge request pipeline.

See: glab ci run

Lint

glab ci lint
glab ci lint --dry-run --ref main

--dry-run simulates pipeline creation, resolving include: and rules; --include-jobs lists the jobs it would produce.

See: glab ci lint

CI variables

glab variable set API_KEY "s3cret42" \
  --masked --protected
glab variable set KUBECONFIG \
  "$(cat kubeconfig)" --type file
glab variable list

--masked hides the value in job logs; --protected limits it to protected branches. -g mygroup sets a group variable.

See: glab variable set

Jobs

Trace

glab ci trace
glab ci trace lint
glab ci trace 224356863 \
  --pipeline-id 42

Without a job, trace prompts from the current branch. The log streams while the job runs.

See: glab ci trace

Retry and cancel

glab ci retry lint
glab ci cancel job 1504182795
glab ci cancel pipeline 42

retry takes a job name or ID; cancel takes job <id> or pipeline <id>. --dry-run previews a job cancel.

See: glab ci retry, glab ci cancel

Artifacts

glab job artifact main build
glab job artifact main build \
  --path dist/
glab job artifact \
  refs/merge-requests/123/head build

The ref is a branch, tag, or refs/merge-requests/<iid>/head. --list-paths prints what was fetched.

See: glab job artifact

Releases

Create

glab release create v1.2.0 \
  --notes "First stable"
glab release create v1.2.0 \
  --notes-file CHANGELOG.md
glab release create v1.2.0 \
  --ref main --tag-message "v1.2.0"

A missing tag is created from the default branch unless --ref names another commit. An existing release is updated, not duplicated.

See: glab release create

Upload assets

glab release upload v1.2.0 dist/*.tgz
glab release upload v1.2.0 \
  'logo.png#Logo#image'

Append #Display name and #type to a path to control how the asset is listed. release create also accepts files after the tag.

See: glab release upload

Download

glab release download
glab release download v1.2.0 \
  --asset-name '*.tar.gz'
glab release download v1.2.0 \
  --dir /tmp --clobber

Without a tag it takes the latest release; --skip-existing fetches only missing files.

See: glab release download

List and view

glab release list
glab release view v1.2.0 --web

Without a tag, release view shows the latest release; --web opens it in the browser.

See: glab release list, glab release view

API and JSON

Call the API

glab api projects/:fullpath
glab api projects/:fullpath/issues
glab api projects/gitlab-org%2Fcli

:fullpath expands from the current project. A path written by hand needs its slash encoded as %2F.

See: glab api

Send a request

glab api --method POST \
  projects/:fullpath/issues \
  -f title="Bug"
glab api --method PUT \
  projects/:fullpath/issues/42 \
  -f state_event=close

-f sends a string; -F converts booleans, numbers, and JSON arrays. A field makes the request a POST, so a GET with params needs an explicit method.

See: REST API

GraphQL

glab api graphql \
  -f query='{ currentUser { username } }'

The query field holds the document; any other field becomes a GraphQL variable. Paginated queries need an $endCursor variable.

See: GraphQL API

Paginate

glab api issues --paginate
glab api issues --paginate \
  --output ndjson \
  | jq 'select(.state == "opened")'

--output ndjson prints one object per line, which streams straight into jq.

See: Pagination

JSON output

glab mr list -F json --jq '.[].title'
glab issue list -O json \
  | jq -r '.[].iid'

Both print JSON: mr list with -F json, issue list with -O json. In glab api, -F is an input field instead.

See: glab mr list

Configuration

Target another project

glab mr list -R group/project
glab issue view 42 -R group/project
glab release list -R group/project

-R accepts GROUP/PROJECT, a subgroup path, or a full URL, for one command only.

See: glab mr

Aliases

glab alias set pv 'mr view'
glab alias set createissue \
  'issue create --title "$1"'
glab alias set --shell igrep \
  'glab issue list | grep "$1"'
glab alias list

$1 and $2 expand arguments. --shell runs the alias through sh, so pipes work and $@ expands to all arguments.

See: glab alias set

Config

glab config set -g editor nvim
glab config get -g host
glab config path

-g writes the global file; without it the setting goes to .git/glab-cli/config.yml for this repository. config edit opens the global file; add --local for the repository file.

See: glab config set

Environment

export GITLAB_TOKEN=glpat-xxxxxxxxxxxx
export GITLAB_HOST=gitlab.example.com
export GLAB_NO_PROMPT=true
export GLAB_CHECK_UPDATE=false

GITLAB_TOKEN beats the stored token; GITLAB_HOST picks the instance. Most config keys have a matching variable.

See: Environment variables

0 Comments for this cheatsheet. Write yours!