glab
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitLab CLI (glab)
GitLab CLI (glab)
Manage GitLab projects entirely from the terminal using . 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环境。
glabWhen 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
前置条件
- installed (
glab,brew install glab, or see https://gitlab.com/gitlab-org/cli)apt install glab - Authenticated via (minimum scopes:
glab auth login,api)write_repository - Inside a Git repository with a GitLab remote (or use to target another project)
-R OWNER/REPO
- 已安装(可通过
glab、brew install glab安装,或查看https://gitlab.com/gitlab-org/cli)apt install glab - 通过完成身份验证(最小权限范围:
glab auth login、api)write_repository - 处于关联GitLab远程仓库的Git代码库中(或使用指定其他项目)
-R OWNER/REPO
Command Structure
命令结构
glab <command> <subcommand> [flags]All commands support / and / (to target a different project).
-h--help-R--repo OWNER/REPOglab <command> <subcommand> [flags]所有命令都支持/和/(用于指定其他项目)。
-h--help-R--repo OWNER/REPOReference Guides
参考指南
| Topic | File | Load when... |
|---|---|---|
| Merge requests | | Creating, reviewing, approving, merging, or listing MRs |
| Issues | | Creating, listing, updating, closing, or triaging issues/incidents |
| CI/CD pipelines & jobs | | Running, viewing, retrying, canceling pipelines or jobs; linting CI config |
| Releases | | Creating releases, uploading assets, managing changelogs |
| Repo, auth & config | | Cloning, forking, creating repos; authenticating; configuring glab |
| API, variables & advanced | | Making raw API calls; managing variables, snippets, schedules, stacks, labels, milestones, aliases |
| Writing issues & MRs | | Writing titles and descriptions for issues or merge requests; following conventional commits; structuring MR descriptions |
| 主题 | 文件 | 加载时机 |
|---|---|---|
| 合并请求 | | 创建、评审、批准、合并或列出MR时 |
| 议题 | | 创建、列出、更新、关闭或分类处理议题/事件时 |
| CI/CD流水线与任务 | | 运行、查看、重试、取消流水线或任务;校验CI配置时 |
| 版本发布 | | 创建版本发布、上传资源、管理变更日志时 |
| 仓库、身份验证与配置 | | 克隆、复刻、创建仓库;身份验证;配置glab时 |
| API、变量与高级功能 | | 直接调用API;管理变量、代码片段、调度、堆叠式差异、标签、里程碑、别名时 |
| 撰写议题与MR | | 为议题或合并请求撰写标题与描述;遵循约定式提交规范;构建MR描述结构时 |
Core Workflows
核心工作流
Create a Merge Request
创建合并请求
Use conventional commit prefixes in titles. See for full guidelines.
references/writing-issues-and-mrs.mdbash
undefined在标题中使用约定式提交前缀。完整指南请查看。
references/writing-issues-and-mrs.mdbash
undefinedInteractive — 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
undefinedglab mr create -f --draft --label WIP
undefinedReview 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 for full guidelines.
references/writing-issues-and-mrs.mdbash
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.mdbash
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 99Run 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.ymlbash
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.0bash
glab release create v1.2.0 ./dist/*.tar.gz \
--notes "Bugfix release" \
--milestone v1.2.0Raw API Calls
直接调用API
bash
undefinedbash
undefinedREST
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
undefinedglab api issues --paginate --output ndjson
undefinedManage Variables
管理变量
bash
glab variable list
glab variable set MY_SECRET "s3cret"
glab variable get MY_SECRET
glab variable delete MY_SECRETbash
glab variable list
glab variable set MY_SECRET "s3cret"
glab variable get MY_SECRET
glab variable delete MY_SECRETAll Top-Level Commands
所有顶层命令
| Command | Purpose |
|---|---|
| Create command shortcuts |
| Make authenticated REST/GraphQL API calls |
| Manage attestations |
| Authenticate to GitLab instances |
| Generate changelogs |
| Check for glab updates |
| Manage CI/CD pipelines and jobs |
| Manage cluster agents |
| Generate shell completions (bash/zsh/fish/PowerShell) |
| Set and get glab configuration |
| Manage deploy keys |
| Interact with GitLab Duo AI |
| Manage GPG keys |
| Manage incidents |
| Manage issues |
| Manage iterations |
| Manage CI/CD jobs |
| Manage labels |
| Model Context Protocol server |
| Manage milestones |
| Manage merge requests |
| OpenTofu integration |
| Manage releases |
| Manage repositories |
| Manage pipeline schedules |
| Manage secure files |
| Manage snippets |
| Manage SSH keys |
| Stacked diffs (experimental) |
| Manage personal access tokens |
| Interact with user accounts |
| Manage CI/CD variables |
| Show glab version |
| 命令 | 用途 |
|---|---|
| 创建命令快捷方式 |
| 发起已验证的REST/GraphQL API调用 |
| 管理证明文件 |
| 验证GitLab实例身份 |
| 生成变更日志 |
| 检查glab更新 |
| 管理CI/CD流水线与任务 |
| 管理集群代理 |
| 生成Shell补全脚本(bash/zsh/fish/PowerShell) |
| 设置与获取glab配置 |
| 管理部署密钥 |
| 与GitLab Duo AI交互 |
| 管理GPG密钥 |
| 管理事件 |
| 管理议题 |
| 管理迭代 |
| 管理CI/CD任务 |
| 管理标签 |
| 模型上下文协议服务器 |
| 管理里程碑 |
| 管理合并请求 |
| OpenTofu集成 |
| 管理版本发布 |
| 管理代码仓库 |
| 管理流水线调度 |
| 管理安全文件 |
| 管理代码片段 |
| 管理SSH密钥 |
| 堆叠式差异(实验性功能) |
| 管理个人访问令牌 |
| 与用户账号交互 |
| 管理CI/CD变量 |
| 显示glab版本 |
Global Flags
全局参数
| Flag | Description |
|---|---|
| Show help for any command |
| Target a different repository (also accepts |
| Show glab version |
| 参数 | 描述 |
|---|---|
| 查看任意命令的帮助信息 |
| 指定其他仓库(也支持 |
| 显示glab版本 |
Tips
小贴士
- Title conventions: Always use conventional commit prefixes for MR titles (,
feat:,fix:, etc.) and descriptive problem-statement titles for issues. Seedocs:.references/writing-issues-and-mrs.md - Auto-detection: glab reads your Git remotes to determine the GitLab project. No need to specify when inside the project directory.
--repo - Multiple instances: Use for each GitLab host. glab picks the right credentials based on your remote URL.
glab auth login - Output formats: Many commands accept
listfor machine-readable output.-F json - Aliases: Create shortcuts with then use
glab alias set mrc 'mr create --fill --yes'.glab mrc - Editor: Set or
EDITORenv vars to control which editor opens for descriptions.VISUAL - Recover: Use on
--recoverandmr createto save progress if creation fails.issue create
- 标题规范:MR标题务必使用约定式提交前缀(、
feat:、fix:等),议题标题使用描述性的问题陈述。详情请查看docs:。references/writing-issues-and-mrs.md - 自动检测:glab会读取Git远程信息来确定GitLab项目,在项目目录内无需指定参数。
--repo - 多实例支持:为每个GitLab主机执行,glab会根据远程URL自动选择正确的凭据。
glab auth login - 输出格式:许多命令支持
list参数以生成机器可读的输出。-F json - 别名设置:通过创建快捷命令,之后即可使用
glab alias set mrc 'mr create --fill --yes'调用。glab mrc - 编辑器设置:设置或
EDITOR环境变量来控制用于编辑描述的编辑器。VISUAL - 恢复进度:在和
mr create命令中使用issue create参数,可在创建失败时保存进度。--recover