关于 gitlab-repo
gitlab-repo 是通过 glab CLI 管理 GitLab 仓库和项目的技能。它涵盖克隆、搜索、转移和删除等常见操作,并标注操作风险。
主要功能
- 01克隆仓库及批量克隆群组仓库
- 02派生并创建仓库
- 03查看和搜索项目
- 04归档、删除和转移仓库
- 05列出仓库贡献者
适用场景
- 01批量克隆团队群组的仓库
- 02派生上游项目以参与贡献
- 03创建或归档 GitLab 项目
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ grandcamel/ gitlab-assistant-skills --skill gitlab-repo安装后在 Claude Code 中输入/gitlab-repo确认已加载。
详细介绍
仓库技能
使用 glab CLI 管理 GitLab 仓库和项目。
快速参考
| 操作 | 命令 | 风险 |
|---|---|---|
| 克隆仓库 | glab repo clone <repo> | - |
| 派生仓库 | glab repo fork <repo> | ⚠️ |
| 查看仓库 | glab repo view | - |
| 创建仓库 | glab repo create | ⚠️ |
| 搜索仓库 | glab repo search <query> | - |
| 归档仓库 | glab repo archive | ⚠️⚠️ |
| 删除仓库 | glab repo delete | ⚠️⚠️⚠️ |
| 列出贡献者 | glab repo contributors | - |
风险说明:- 安全 | ⚠️ 谨慎 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险
何时使用此技能
始终在以下情况下使用:
- 用户想要克隆、派生或创建仓库
- 用户提到“repo”“repository”“project”“clone”“fork”
- 用户想要管理项目设置
以下情况绝不使用:
- 用户想要处理特定仓库的内容(直接使用 git)
- 用户想要管理部署密钥(使用 gitlab-deploy-key 技能)
可用命令
克隆仓库
glab repo clone <repo> [directory] [options]
参数:
<repo>- 仓库路径、URL 或项目 ID[directory]- 可选的本地目录名称
选项:
| 标志 | 说明 |
|---|---|
-g, --group=<group> | 克隆某个群组中的所有仓库 |
-p, --preserve-namespace | 根据命名空间在子目录中克隆 |
-a, --archived=<bool> | 包含或排除已归档的仓库(与 -g 一起使用) |
--paginate | 获取项目的所有分页(与 -g 一起使用) |
示例:
# Clone by path
glab repo clone gitlab-org/cli
# Clone by URL
glab repo clone https://gitlab.com/gitlab-org/cli
# Clone into specific directory
glab repo clone gitlab-org/cli my-glab
# Clone by project ID
glab repo clone 4356677
# Clone preserving namespace structure
glab repo clone gitlab-org/cli -p
# Creates: gitlab-org/cli/
# Clone all repos in a group
glab repo clone -g mygroup --paginate
# Clone only non-archived repos from group
glab repo clone -g mygroup --archived=false --paginate
派生仓库
glab repo fork <repo> [options]
选项:
| 标志 | 说明 |
|---|---|
-c, --clone | 创建派生仓库后将其克隆 |
-n, --name=<name> | 派生项目的名称 |
-p, --path=<path> | 派生项目的路径 |
--remote | 为派生仓库添加远程仓库 |
示例:
# Fork a repository
glab repo fork owner/repo
# Fork and clone
glab repo fork owner/repo --clone
# Fork with custom name
glab repo fork owner/repo --name="my-fork"
# Fork and add remote
glab repo fork owner/repo --remote
查看仓库
glab repo view [repo] [options]
选项:
| 标志 | 说明 |
|---|---|
-w, --web | 在浏览器中打开仓库 |
-b, --branch=<branch> | 查看指定分支 |
示例:
# View current repository info
glab repo view
# View specific repo
glab repo view gitlab-org/cli
# Open in browser
glab repo view --web
# View specific branch
glab repo view --branch=develop
创建仓库
glab repo create [name] [options]
选项:
| 标志 | 说明 |
|---|---|
-n, --name=<name> | 仓库名称 |
-d, --description=<desc> | 仓库描述 |
-g, --group=<group> | 在指定群组/命名空间中创建 |
--public | 将仓库设为公开 |
--private | 将仓库设为私有 |
--internal | 将仓库设为内部可见 |
--readme | 使用 README 初始化 |
-c, --clone | 创建后克隆 |
示例:
# Create repository interactively
glab repo create
# Create with name and description
glab repo create my-project -d "My awesome project"
# Create public repo in group
glab repo create my-project --group=myteam --public
# Create and clone
glab repo create my-project --clone --readme
搜索仓库
glab repo search <query> [options]
选项:
| 标志 | 说明 |
|---|---|
-P, --per-page=<n> | 每页结果数 |
--all | 获取所有结果 |
示例:
# Search for repos
glab repo search "cli tools"
# Search with more results
glab repo search "gitlab" --per-page=50
归档仓库
glab repo archive [repo] [options]
归档仓库(使其变为只读)。
示例:
# Archive current repo
glab repo archive
# Archive specific repo
glab repo archive owner/repo
删除仓库
glab repo delete [repo] [options]
**警告:**此操作会永久删除仓库及其所有数据!
选项:
| 标志 | 说明 |
|---|---|
-y, --yes | 跳过确认提示 |
示例:
# Delete repo (will prompt for confirmation)
glab repo delete owner/repo
# Delete without confirmation (dangerous!)
glab repo delete owner/repo --yes
列出贡献者
glab repo contributors [repo] [options]
选项:
| 标志 | 说明 |
|---|---|
-P, --per-page=<n> | 每页结果数 |
--order=<order> | 排序方式:name、email、commits |
示例:
# List contributors for current repo
glab repo contributors
# List with sorting
glab repo contributors --order=commits
转移仓库
glab repo transfer <repo> <new-namespace>
将仓库转移到另一个命名空间。
示例:
# Transfer to different group
glab repo transfer myrepo newgroup
常见工作流
工作流 1:派生并贡献代码
# 1. Fork the repository
glab repo fork upstream/project --clone
# 2. Add upstream remote
cd project
git remote add upstream https://gitlab.com/upstream/project.git
# 3. Create feature branch
git checkout -b feature/my-change
# 4. Make changes, commit, push
git add . && git commit -m "Add feature"
git push -u origin feature/my-change
# 5. Create MR to upstream
glab mr create --target-branch=main
工作流 2:批量克隆团队仓库
# Clone all non-archived repos from team group
glab repo clone -g myteam --archived=false --paginate -p
# This creates:
# myteam/
# repo1/
# repo2/
# ...
工作流 3:创建新项目
# 1. Create the repository
glab repo create awesome-project \
-d "An awesome new project" \
--group=myteam \
--readme \
--clone
# 2. Set up the project
cd awesome-project
# Add initial files...
# 3. View it in browser
glab repo view --web
故障排除
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 身份验证失败 | 令牌无效或已过期 | 运行 glab auth login |
| 找不到仓库 | 路径无效或无权访问 | 检查仓库路径和权限 |
| 克隆失败 | 未配置 SSH 密钥 | 使用 HTTPS 或配置 SSH 密钥 |
| 无法派生 | 已经派生或没有权限 | 检查现有派生仓库 |
| 无法删除 | 不是所有者或维护者 | 请仓库所有者删除 |
Related Documentation
评论
支持 Markdown