SuperAPI AI Directory

gitlab-cli-guide

Coding & development

View repository

Updated 11-06 17:19

About this skill

GitLab CLI Skill Set

Complete command reference and workflow guide for GitLab CLI (glab).

Quick Start

# 首次配置
glab auth login

# 常用操作
glab mr create --fill              # 从当前分支创建合并请求
glab issue create                  # 创建 Issue
glab ci view                       # 查看流水线状态
glab repo view --web              # 在浏览器中打开仓库

Skill Organization Structure

This skill routes to specialized sub-skills by GitLab functional domain:

Core Workflows:

  • glab-mr - Merge Requests: create, review, approve, merge
  • glab-issue - Issues: create, list, update, close, comment
  • glab-ci - CI/CD: pipelines, jobs, logs, artifacts
  • glab-repo - Repositories: clone, create, fork, manage

Project Management:

  • glab-milestone - Release planning and milestone tracking
  • glab-iteration - Sprint/iteration management
  • glab-label - Label management and categorization
  • glab-release - Software releases and version management

Authentication and Configuration:

  • glab-auth - Login, logout, Docker Registry authentication
  • glab-config - CLI configuration and default settings
  • glab-ssh-key - SSH key management
  • glab-gpg-key - GPG keys (for commit signing)
  • glab-token - Personal and project access tokens

CI/CD Management:

  • glab-job - Individual job operations
  • glab-schedule - Scheduled pipelines and Cron jobs
  • glab-variable - CI/CD variables and secrets
  • glab-securefile - Pipeline secure files
  • glab-runner - Runner management: list, pause, delete (new in v1.87.0)
  • glab-runner-controller - Runner controllers and token management (experimental, administrators only)

Collaboration:

  • glab-user - User profiles and information
  • glab-snippet - Snippets (similar to GitLab Gist)
  • glab-incident - Incident management
  • glab-workitems - Work items: tasks, OKRs, key results, next-generation Epics (new in v1.87.0)

Advanced:

  • glab-api - Direct REST API calls
  • glab-cluster - Kubernetes cluster integration
  • glab-deploy-key - Deploy keys (for automation)
  • glab-stack - Stacked/dependent merge requests
  • glab-opentofu - Terraform/OpenTofu state management

Tools:

  • glab-alias - Custom command aliases
  • glab-completion - Shell autocompletion
  • glab-help - Command help and documentation
  • glab-version - Version information
  • glab-check-update - Update checks
  • glab-changelog - Changelog generation
  • glab-attestation - Software supply chain security
  • glab-duo - GitLab Duo AI assistant
  • glab-mcp - Model Context Protocol server for AI assistant integration (experimental)

When to Use glab vs. the Web Interface

Scenarios suitable for using glab:

  • Automating GitLab operations in scripts
  • Terminal-centric workflows
  • Batch operations (processing multiple MRs/Issues)
  • Integration with other CLI tools
  • CI/CD pipeline workflows
  • Quick navigation without switching to a browser

Scenarios suitable for using the Web interface:

  • Complex diff review with inline comments
  • Visual merge conflict resolution
  • Configuring repository settings and permissions
  • Advanced search/filtering across projects
  • View security scan results
  • Manage group/instance-level settings

Common workflows

Daily development

# 开始处理某个 Issue
glab issue view 123
git checkout -b 123-feature-name

# 准备好后创建 MR
glab mr create --fill --draft

# 标记为可审查
glab mr update --ready

# 审批通过后合并
glab mr merge --when-pipeline-succeeds --remove-source-branch

Code review

# 查看待审查列表
glab mr list --reviewer=@me --state=opened

# 审查某个 MR
glab mr checkout 456
glab mr diff
npm test

# 批准
glab mr approve 456
glab mr note 456 -m "LGTM! Nice work on the error handling."

CI/CD debugging

# 检查流水线状态
glab ci status

# 查看失败的任务
glab ci view

# 获取任务日志
glab ci trace <job-id>

# 重试失败的任务
glab ci retry <job-id>

Decision tree

"Should I create an MR first or an Issue first?"

需要跟踪工作进度?
├─ 是 → 先创建 Issue(glab issue create)
│         然后:glab mr for <issue-id>
└─ 否 → 直接创建 MR(glab mr create --fill)

Scenarios for using glab issue create + glab mr for :

  • Discussion/approval needed before coding
  • Tracking feature requests or bugs
  • Sprint planning and assignment
  • Want the Issue to close automatically when the MR is merged

Scenarios for using glab mr create directly:

  • Quick fixes or typos
  • An existing Issue is already being handled
  • Urgent fixes or hotfixes

"Which CI command should I use?"

你需要什么?
├─ 查看流水线整体状态 → glab ci status
├─ 可视化流水线视图 → glab ci view
├─ 查看特定任务日志 → glab ci trace <job-id>
├─ 下载构建产物 → glab ci artifact <ref> <job-name>
├─ 验证配置文件 → glab ci lint
├─ 触发新运行 → glab ci run
└─ 列出所有流水线 → glab ci list

Quick reference:

  • Pipeline level:glab ci status、glab ci view、glab ci run
  • Job level:glab ci trace、glab job retry、glab job view
  • Artifacts:glab ci artifact(by pipeline) or get job artifacts via glab job Get task artifacts

"Clone or Fork?"

你与仓库的关系?
├─ 有写入权限 → glab repo clone group/project
├─ 向他人项目贡献代码:
│   ├─ 一次性贡献 → glab repo fork + 工作 + MR
│   └─ 持续贡献 → glab repo fork,然后定期同步
└─ 仅阅读/浏览 → glab repo clone(或 view --web)

Scenarios suited for Fork:

  • No write access to the original repository
  • Contributing code to open source projects
  • Experimenting without affecting the original repository
  • Need your own copy for long-term work

Scenarios suited for Clone:

  • You are a project member with write access
  • Working on an organization/team repository
  • No personal copy needed

"Project labels or group labels?"

标签应该放在哪?
├─ 跨多个项目使用 → glab label create --group <group>
└─ 仅限某个项目 → glab label create(在项目目录中)

Group-level labels:

  • Unified label system across the organization
  • Examples: priority::high, type::bug, status::blocked
  • Centrally managed, automatically inherited by projects

Project-level labels:

  • Project-specific workflows
  • Examples: needs-ux-review, deploy-to-staging
  • Managed by project maintainers

Related skills

MR and Issue workflows:

  • Start creating/tracking work from glab-issue Start creating/tracking work
  • Use glab-mr to create an MR that closes an Issue
  • Script:scripts/create-mr-from-issue.sh automates this process

CI/CD debugging:

  • Use glab-ci for pipeline-level operations
  • Use glab-job for single job operations
  • Script:scripts/ci-debug.sh quickly diagnoses failure causes

Repository operations:

  • Use glab-repo for repository management
  • Use glab-auth for authentication configuration
  • Script:scripts/sync-fork.sh syncs forks

Configuration:

  • Use glab-auth for initial authentication
  • Use glab-config to set defaults and preferences
  • Use glab-alias to create custom shortcuts