GitLab CLI (glab) Skill
Use glab when the user wants to operate on GitLab from the terminal. These instructions are verified against glab 1.90.0.
This hot path is intentionally narrow: merge requests, issues, CI/CD, repo targeting, repo view/clone/fork, and glab api. Broader project administration should only be documented through a dedicated reference file.
When to Use
Invoke this skill when the user needs to:
- - Create, review, update, merge, or inspect merge requests
- Create, inspect, or update issues
- Check, run, retry, cancel, or inspect CI/CD pipelines and jobs
- Target a repository explicitly, or view, clone, or fork it
- Work with self-hosted GitLab instances
- Make direct GitLab REST or GraphQL API calls with INLINECODE3
Preflight
Run these checks before doing real work:
CODEBLOCK0
If not inside a Git repository, do not guess context. Use one of these patterns instead:
CODEBLOCK1
For self-hosted GitLab, set the host explicitly when needed:
CODEBLOCK2
Execution Policy
- - Prefer read-only commands first:
list, view, status, trace. - Prefer structured output when the user wants filtering or automation:
-
--output json for
mr,
ci, and
repo commands
-
-O json for
issue list
-
--output ndjson for large
glab api --paginate responses piped to
jq
- - Before remote mutations, confirm the repository, target object, and branch. This matters for
mr create, mr merge, mr close, issue close, ci run, ci retry, ci cancel, ci delete, and repo fork commands. - If
glab auth status shows missing or invalid credentials, stop and ask the user to authenticate instead of retrying failing API calls. - Use
glab <command> --help before guessing flags. CLI behavior changes across releases. - For
glab api, pagination belongs in the endpoint query string. Example:
CODEBLOCK3
Common Workflows
Merge Requests
CODEBLOCK4
INLINECODE29 sets push to true. Confirm git status, the current branch, and the target remote before using --fill --yes.
Issues
CODEBLOCK5
CI/CD
CODEBLOCK6
References
Load only the smallest file that matches the task:
- -
references/quick-reference.md for a short cheat sheet - INLINECODE34 for authentication, repo context, self-hosted hosts, and 401/403/404 errors
- INLINECODE35 for MR workflows, comments, merge strategies, and MR-specific failures
- INLINECODE36 for issue creation, editing, linking, and issue-specific failures
- INLINECODE37 for pipeline and job inspection, reruns, cancelation, variables, and CI failures
- INLINECODE38 for
glab api, pagination, GraphQL, and automation patterns
Load a reference only when the task needs deeper flags, examples, or troubleshooting than this file provides.
GitLab CLI (glab) 技能
当用户想要在终端中操作 GitLab 时,使用 glab。这些说明已针对 glab 1.90.0 版本验证。
此热路径特意限定范围:合并请求、议题、CI/CD、仓库定位、仓库查看/克隆/复刻,以及 glab api。更广泛的项目管理应仅通过专门的参考文件进行记录。
使用时机
当用户需要以下操作时,调用此技能:
- - 创建、审查、更新、合并或检查合并请求
- 创建、检查或更新议题
- 检查、运行、重试、取消或检查 CI/CD 流水线和作业
- 显式定位仓库,或查看、克隆、复刻仓库
- 使用自托管 GitLab 实例
- 使用 glab api 直接调用 GitLab REST 或 GraphQL API
前置检查
在执行实际操作前,运行以下检查:
bash
glab --version
glab auth status
git remote -v
如果不在 Git 仓库内,不要猜测上下文。应使用以下模式之一:
bash
glab mr list -R group/project
glab issue list -R group/project
glab repo view group/project
glab repo view https://gitlab.example.org/group/project.git
对于自托管 GitLab,在需要时显式设置主机:
bash
glab auth login --hostname gitlab.example.org
GITLAB_HOST=gitlab.example.org glab repo view group/project
glab api --hostname gitlab.example.org projects/:id
执行策略
- - 优先使用只读命令:list、view、status、trace。
- 当用户需要过滤或自动化时,优先使用结构化输出:
- mr、ci 和 repo 命令使用 --output json
- issue list 使用 -O json
- 对于通过管道传递给 jq 的大型 glab api --paginate 响应,使用 --output ndjson
- - 在远程修改前,确认仓库、目标对象和分支。这对 mr create、mr merge、mr close、issue close、ci run、ci retry、ci cancel、ci delete 和 repo fork 命令至关重要。
- 如果 glab auth status 显示凭据缺失或无效,停止操作并要求用户进行身份验证,而不是重试失败的 API 调用。
- 在猜测标志之前,使用 glab --help。CLI 行为在不同版本间可能发生变化。
- 对于 glab api,分页应包含在端点查询字符串中。示例:
bash
glab api projects/:id/jobs?per_page=100 --paginate --output ndjson
常见工作流程
合并请求
bash
glab mr list --reviewer=@me --output json
glab mr checkout 123
glab mr view 123 --comments
glab mr create -t 添加功能 -d 实现X功能 --reviewer alice,bob -l feature
glab mr create --related-issue 123 --fill --yes
glab mr update 123 --ready
glab mr note 123 -m 请添加测试
glab mr merge 123 --auto-merge
glab mr create --fill 会将 push 设置为 true。在使用 --fill --yes 前,确认 git status、当前分支和目标远程仓库。
议题
bash
glab issue list --assignee=@me -O json
glab issue view 456 --comments
glab issue create -t 登录错误 -l bug -d 复现步骤
glab issue update 456 --label bug,confirmed
glab issue close 456
CI/CD
bash
glab ci list -s failed -F json
glab ci status --live
glab pipeline ci view -b main
glab ci trace lint
glab ci run -b main --variables DEPLOY_ENV:staging
glab ci retry lint
glab ci cancel pipeline 123
参考资料
仅加载与任务匹配的最小文件:
- - references/quick-reference.md:快速参考手册
- references/auth.md:身份验证、仓库上下文、自托管主机和 401/403/404 错误
- references/merge-requests.md:合并请求工作流程、评论、合并策略和 MR 特定错误
- references/issues.md:议题创建、编辑、关联和议题特定错误
- references/ci.md:流水线和作业检查、重新运行、取消、变量和 CI 错误
- references/api.md:glab api、分页、GraphQL 和自动化模式
仅当任务需要比此文件提供的更深入的标志、示例或故障排除时,才加载参考资料。