GitLab CLI (glab)
When to use
- Create or review merge requests, issues, milestones, and labels from the shell.
- Inspect or retry pipelines and jobs (
glab ci,glab job). - Call the GitLab HTTP API via
glab apiwith the same auth as the CLI.
Prerequisites
glabinstalled (glab version). Install and reference: GitLab CLI documentation.- Auth:
glab auth login(interactive) or tokens. Common env vars:GITLAB_TOKEN(orGITLAB_ACCESS_TOKEN/OAUTH_TOKENper deployment)GITLAB_HOSTorGL_HOSTfor self-managed GitLab (e.g.https://gitlab.example.com)
- In GitLab CI,
GLAB_ENABLE_CI_AUTOLOGIN=truecan useCI_JOB_TOKENfor supported commands; token precedence is documented upstream.
Patterns
- Help:
glab --help,glab <cmd> --help. - Repo scope: from current directory’s Git remote, or
-R group/project/--repowhere supported. - JSON: many commands offer
-F jsonor--output json(check each command’s help).
Core commands (orienting)
| Area | Examples |
|---|---|
| Auth | glab auth status, glab auth login |
| MRs | glab mr list, glab mr create, glab mr view, glab mr checkout <id>, glab mr approve |
| Issues | glab issue list, glab issue create, glab issue view |
| CI/CD | glab ci view, glab ci list, glab job trace (exact subcommands: glab ci --help) |
| Repo | glab repo clone, glab repo view |
| API | glab api projects/:id (paths and methods: glab api --help) |
Safety
- Treat
GITLAB_TOKENlike a password; never echo it in logs. - Destructive operations (merge, delete, pipeline retry) require explicit user alignment.
References
- Official documentation: GitLab CLI
- Local help:
glab --help,glab <cmd> --help(authoritative for your installedglabversion)