glab

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitLab CLI (glab)

GitLab CLI (glab)

Manage GitLab projects entirely from the terminal using
glab
. This skill covers creating merge requests, triaging issues, running pipelines, cutting releases, and making raw API calls — all without leaving your shell.
使用
glab
完全从终端管理GitLab项目。本技能涵盖创建合并请求、分类处理议题、运行流水线、创建版本发布以及直接调用API——所有操作都无需离开你的Shell环境。

When to Use

使用场景

  • Creating, reviewing, approving, or merging merge requests
  • Creating, listing, updating, or closing issues and incidents
  • Running, retrying, canceling, or viewing CI/CD pipelines and jobs
  • Creating releases with assets and changelogs
  • Cloning, forking, or managing repositories
  • Managing CI/CD variables, schedules, and snippets
  • Making raw REST or GraphQL API calls to GitLab
  • Working with stacked diffs (experimental)
  • Managing labels, milestones, deploy keys, SSH/GPG keys
  • Authenticating to GitLab instances
  • 创建、评审、批准或合并合并请求
  • 创建、列出、更新或关闭议题与事件
  • 运行、重试、取消或查看CI/CD流水线与任务
  • 创建包含资源和变更日志的版本发布
  • 克隆、复刻或管理代码仓库
  • 管理CI/CD变量、调度与代码片段
  • 直接调用GitLab的REST或GraphQL API
  • 处理堆叠式差异(实验性功能)
  • 管理标签、里程碑、部署密钥、SSH/GPG密钥
  • 验证GitLab实例身份

Prerequisites

前置条件

  • glab
    installed (
    brew install glab
    ,
    apt install glab
    , or see https://gitlab.com/gitlab-org/cli)
  • Authenticated via
    glab auth login
    (minimum scopes:
    api
    ,
    write_repository
    )
  • Inside a Git repository with a GitLab remote (or use
    -R OWNER/REPO
    to target another project)
  • 已安装
    glab
    (可通过
    brew install glab
    apt install glab
    安装,或查看https://gitlab.com/gitlab-org/cli)
  • 通过
    glab auth login
    完成身份验证(最小权限范围:
    api
    write_repository
  • 处于关联GitLab远程仓库的Git代码库中(或使用
    -R OWNER/REPO
    指定其他项目)

Command Structure

命令结构

glab <command> <subcommand> [flags]
All commands support
-h
/
--help
and
-R
/
--repo OWNER/REPO
(to target a different project).
glab <command> <subcommand> [flags]
所有命令都支持
-h
/
--help
-R
/
--repo OWNER/REPO
(用于指定其他项目)。

Reference Guides

参考指南

TopicFileLoad when...
Merge requests
references/merge-requests.md
Creating, reviewing, approving, merging, or listing MRs
Issues
references/issues.md
Creating, listing, updating, closing, or triaging issues/incidents
CI/CD pipelines & jobs
references/ci-cd.md
Running, viewing, retrying, canceling pipelines or jobs; linting CI config
Releases
references/releases.md
Creating releases, uploading assets, managing changelogs
Repo, auth & config
references/repo-and-config.md
Cloning, forking, creating repos; authenticating; configuring glab
API, variables & advanced
references/api-and-advanced.md
Making raw API calls; managing variables, snippets, schedules, stacks, labels, milestones, aliases
Writing issues & MRs
references/writing-issues-and-mrs.md
Writing titles and descriptions for issues or merge requests; following conventional commits; structuring MR descriptions
主题文件加载时机
合并请求
references/merge-requests.md
创建、评审、批准、合并或列出MR时
议题
references/issues.md
创建、列出、更新、关闭或分类处理议题/事件时
CI/CD流水线与任务
references/ci-cd.md
运行、查看、重试、取消流水线或任务;校验CI配置时
版本发布
references/releases.md
创建版本发布、上传资源、管理变更日志时
仓库、身份验证与配置
references/repo-and-config.md
克隆、复刻、创建仓库;身份验证;配置glab时
API、变量与高级功能
references/api-and-advanced.md
直接调用API;管理变量、代码片段、调度、堆叠式差异、标签、里程碑、别名时
撰写议题与MR
references/writing-issues-and-mrs.md
为议题或合并请求撰写标题与描述;遵循约定式提交规范;构建MR描述结构时

Core Workflows

核心工作流

Create a Merge Request

创建合并请求

Use conventional commit prefixes in titles. See
references/writing-issues-and-mrs.md
for full guidelines.
bash
undefined
在标题中使用约定式提交前缀。完整指南请查看
references/writing-issues-and-mrs.md
bash
undefined

Interactive — prompts for title, description, target branch

交互式模式——提示输入标题、描述、目标分支

glab mr create
glab mr create

Non-interactive with conventional title, reviewers, and labels

非交互式模式,使用约定式标题、指定处理人与评审人,并添加标签

glab mr create -t "feat(auth): add OAuth2 login (closes #123)" --yes -a assignee --reviewer reviewer1 --label "ready for review" -b main
glab mr create -t "feat(auth): add OAuth2 login (closes #123)" --yes -a assignee --reviewer reviewer1 --label "ready for review" -b main

Draft MR from commit info

根据提交信息创建草稿MR

glab mr create -f --draft --label WIP
undefined
glab mr create -f --draft --label WIP
undefined

Review and Merge

评审与合并

bash
glab mr list --reviewer=@me          # MRs awaiting your review
glab mr diff 42                       # View changes
glab mr approve 42                    # Approve
glab mr merge 42                      # Merge (prompts for method)
bash
glab mr list --reviewer=@me          # 等待我评审的MR
glab mr diff 42                       # 查看变更内容
glab mr approve 42                    # 批准MR
glab mr merge 42                      # 合并MR(提示选择合并方式)

Create an Issue

创建议题

Use descriptive titles with type prefixes. See
references/writing-issues-and-mrs.md
for full guidelines.
bash
glab issue create -t "[Bug]: Login fails on iOS Safari 17 after timeout" -l bug,P1 -m v2.0
glab issue list --label bug --assignee=@me
glab issue close 99
使用带类型前缀的描述性标题。完整指南请查看
references/writing-issues-and-mrs.md
bash
glab issue create -t "[Bug]: Login fails on iOS Safari 17 after timeout" -l bug,P1 -m v2.0
glab issue list --label bug --assignee=@me
glab issue close 99

Run and Monitor CI/CD

运行与监控CI/CD

bash
glab ci run -b main                   # Trigger pipeline on branch
glab ci status                        # Current pipeline status
glab ci view                          # Interactive pipeline viewer
glab ci retry lint                    # Retry a specific job by name
glab ci lint                          # Validate .gitlab-ci.yml
bash
glab ci run -b main                   # 触发main分支的流水线
glab ci status                        # 当前流水线状态
glab ci view                          # 交互式流水线查看器
glab ci retry lint                    # 按名称重试特定任务
glab ci lint                          # 校验.gitlab-ci.yml文件

Create a Release

创建版本发布

bash
glab release create v1.2.0 ./dist/*.tar.gz \
  --notes "Bugfix release" \
  --milestone v1.2.0
bash
glab release create v1.2.0 ./dist/*.tar.gz \
  --notes "Bugfix release" \
  --milestone v1.2.0

Raw API Calls

直接调用API

bash
undefined
bash
undefined

REST

REST API调用

glab api projects/:fullpath/members
glab api projects/:fullpath/members

GraphQL

GraphQL API调用

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

With pagination

分页调用

glab api issues --paginate --output ndjson
undefined
glab api issues --paginate --output ndjson
undefined

Manage Variables

管理变量

bash
glab variable list
glab variable set MY_SECRET "s3cret"
glab variable get MY_SECRET
glab variable delete MY_SECRET
bash
glab variable list
glab variable set MY_SECRET "s3cret"
glab variable get MY_SECRET
glab variable delete MY_SECRET

All Top-Level Commands

所有顶层命令

CommandPurpose
glab alias
Create command shortcuts
glab api
Make authenticated REST/GraphQL API calls
glab attestation
Manage attestations
glab auth
Authenticate to GitLab instances
glab changelog
Generate changelogs
glab check-update
Check for glab updates
glab ci
Manage CI/CD pipelines and jobs
glab cluster
Manage cluster agents
glab completion
Generate shell completions (bash/zsh/fish/PowerShell)
glab config
Set and get glab configuration
glab deploy-key
Manage deploy keys
glab duo
Interact with GitLab Duo AI
glab gpg-key
Manage GPG keys
glab incident
Manage incidents
glab issue
Manage issues
glab iteration
Manage iterations
glab job
Manage CI/CD jobs
glab label
Manage labels
glab mcp
Model Context Protocol server
glab milestone
Manage milestones
glab mr
Manage merge requests
glab opentofu
OpenTofu integration
glab release
Manage releases
glab repo
Manage repositories
glab schedule
Manage pipeline schedules
glab securefile
Manage secure files
glab snippet
Manage snippets
glab ssh-key
Manage SSH keys
glab stack
Stacked diffs (experimental)
glab token
Manage personal access tokens
glab user
Interact with user accounts
glab variable
Manage CI/CD variables
glab version
Show glab version
命令用途
glab alias
创建命令快捷方式
glab api
发起已验证的REST/GraphQL API调用
glab attestation
管理证明文件
glab auth
验证GitLab实例身份
glab changelog
生成变更日志
glab check-update
检查glab更新
glab ci
管理CI/CD流水线与任务
glab cluster
管理集群代理
glab completion
生成Shell补全脚本(bash/zsh/fish/PowerShell)
glab config
设置与获取glab配置
glab deploy-key
管理部署密钥
glab duo
与GitLab Duo AI交互
glab gpg-key
管理GPG密钥
glab incident
管理事件
glab issue
管理议题
glab iteration
管理迭代
glab job
管理CI/CD任务
glab label
管理标签
glab mcp
模型上下文协议服务器
glab milestone
管理里程碑
glab mr
管理合并请求
glab opentofu
OpenTofu集成
glab release
管理版本发布
glab repo
管理代码仓库
glab schedule
管理流水线调度
glab securefile
管理安全文件
glab snippet
管理代码片段
glab ssh-key
管理SSH密钥
glab stack
堆叠式差异(实验性功能)
glab token
管理个人访问令牌
glab user
与用户账号交互
glab variable
管理CI/CD变量
glab version
显示glab版本

Global Flags

全局参数

FlagDescription
-h, --help
Show help for any command
-R, --repo OWNER/REPO
Target a different repository (also accepts
GROUP/NAMESPACE/REPO
or full URL)
-v, --version
Show glab version
参数描述
-h, --help
查看任意命令的帮助信息
-R, --repo OWNER/REPO
指定其他仓库(也支持
GROUP/NAMESPACE/REPO
或完整URL)
-v, --version
显示glab版本

Tips

小贴士

  • Title conventions: Always use conventional commit prefixes for MR titles (
    feat:
    ,
    fix:
    ,
    docs:
    , etc.) and descriptive problem-statement titles for issues. See
    references/writing-issues-and-mrs.md
    .
  • Auto-detection: glab reads your Git remotes to determine the GitLab project. No need to specify
    --repo
    when inside the project directory.
  • Multiple instances: Use
    glab auth login
    for each GitLab host. glab picks the right credentials based on your remote URL.
  • Output formats: Many
    list
    commands accept
    -F json
    for machine-readable output.
  • Aliases: Create shortcuts with
    glab alias set mrc 'mr create --fill --yes'
    then use
    glab mrc
    .
  • Editor: Set
    EDITOR
    or
    VISUAL
    env vars to control which editor opens for descriptions.
  • Recover: Use
    --recover
    on
    mr create
    and
    issue create
    to save progress if creation fails.
  • 标题规范:MR标题务必使用约定式提交前缀(
    feat:
    fix:
    docs:
    等),议题标题使用描述性的问题陈述。详情请查看
    references/writing-issues-and-mrs.md
  • 自动检测:glab会读取Git远程信息来确定GitLab项目,在项目目录内无需指定
    --repo
    参数。
  • 多实例支持:为每个GitLab主机执行
    glab auth login
    ,glab会根据远程URL自动选择正确的凭据。
  • 输出格式:许多
    list
    命令支持
    -F json
    参数以生成机器可读的输出。
  • 别名设置:通过
    glab alias set mrc 'mr create --fill --yes'
    创建快捷命令,之后即可使用
    glab mrc
    调用。
  • 编辑器设置:设置
    EDITOR
    VISUAL
    环境变量来控制用于编辑描述的编辑器。
  • 恢复进度:在
    mr create
    issue create
    命令中使用
    --recover
    参数,可在创建失败时保存进度。