gitlab-repo

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Repository Skill

仓库操作技能

Repository and project operations for GitLab using the
glab
CLI.
使用
glab
CLI进行GitLab仓库与项目操作。

Quick Reference

快速参考

OperationCommandRisk
Clone repo
glab repo clone <repo>
-
Fork repo
glab repo fork <repo>
⚠️
View repo
glab repo view
-
Create repo
glab repo create
⚠️
Search repos
glab repo search <query>
-
Archive repo
glab repo archive
⚠️⚠️
Delete repo
glab repo delete
⚠️⚠️⚠️
List contributors
glab repo contributors
-
Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger
操作命令风险
克隆仓库
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
-
风险说明: - 安全 | ⚠️ 注意 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险

When to Use This Skill

何时使用此技能

ALWAYS use when:
  • User wants to clone, fork, or create repositories
  • User mentions "repo", "repository", "project", "clone", "fork"
  • User wants to manage project settings
NEVER use when:
  • User wants to work with specific repo content (use git directly)
  • User wants to manage deploy keys (use gitlab-deploy-key skill)
请务必在以下场景使用:
  • 用户需要克隆、复刻或创建仓库
  • 用户提及“repo”、“repository”、“project”、“clone”、“fork”
  • 用户需要管理项目设置
请勿在以下场景使用:
  • 用户需要处理仓库特定内容(直接使用git)
  • 用户需要管理部署密钥(使用gitlab-deploy-key技能)

Available Commands

可用命令

Clone Repository

克隆仓库

bash
glab repo clone <repo> [directory] [options]
Arguments:
  • <repo>
    - Repository path, URL, or project ID
  • [directory]
    - Optional local directory name
Options:
FlagDescription
-g, --group=<group>
Clone all repos in a group
-p, --preserve-namespace
Clone into subdirectory based on namespace
-a, --archived=<bool>
Include/exclude archived repos (with -g)
--paginate
Fetch all pages of projects (with -g)
Examples:
bash
undefined
bash
glab repo clone <repo> [directory] [options]
参数:
  • <repo>
    - 仓库路径、URL或项目ID
  • [directory]
    - 可选的本地目录名称
选项:
标志描述
-g, --group=<group>
克隆组内所有仓库
-p, --preserve-namespace
根据命名空间克隆到子目录
-a, --archived=<bool>
包含/排除已归档仓库(搭配-g使用)
--paginate
获取所有分页的项目(搭配-g使用)
示例:
bash
undefined

Clone by path

通过路径克隆

glab repo clone gitlab-org/cli
glab repo clone gitlab-org/cli

Clone by URL

通过URL克隆

Clone into specific directory

克隆到指定目录

glab repo clone gitlab-org/cli my-glab
glab repo clone gitlab-org/cli my-glab

Clone by project ID

通过项目ID克隆

glab repo clone 4356677
glab repo clone 4356677

Clone preserving namespace structure

保留命名空间结构克隆

glab repo clone gitlab-org/cli -p
glab repo clone gitlab-org/cli -p

Creates: gitlab-org/cli/

生成目录: gitlab-org/cli/

Clone all repos in a group

克隆组内所有仓库

glab repo clone -g mygroup --paginate
glab repo clone -g mygroup --paginate

Clone only non-archived repos from group

克隆组内未归档的仓库

glab repo clone -g mygroup --archived=false --paginate
undefined
glab repo clone -g mygroup --archived=false --paginate
undefined

Fork Repository

复刻仓库

bash
glab repo fork <repo> [options]
Options:
FlagDescription
-c, --clone
Clone the fork after creating
-n, --name=<name>
Name for the forked project
-p, --path=<path>
Path for the forked project
--remote
Add a remote for the fork
Examples:
bash
undefined
bash
glab repo fork <repo> [options]
选项:
标志描述
-c, --clone
创建复刻后克隆仓库
-n, --name=<name>
复刻项目的名称
-p, --path=<path>
复刻项目的路径
--remote
为复刻添加远程仓库
示例:
bash
undefined

Fork a repository

复刻仓库

glab repo fork owner/repo
glab repo fork owner/repo

Fork and clone

复刻并克隆

glab repo fork owner/repo --clone
glab repo fork owner/repo --clone

Fork with custom name

自定义名称复刻

glab repo fork owner/repo --name="my-fork"
glab repo fork owner/repo --name="my-fork"

Fork and add remote

复刻并添加远程仓库

glab repo fork owner/repo --remote
undefined
glab repo fork owner/repo --remote
undefined

View Repository

查看仓库

bash
glab repo view [repo] [options]
Options:
FlagDescription
-w, --web
Open repository in browser
-b, --branch=<branch>
View specific branch
Examples:
bash
undefined
bash
glab repo view [repo] [options]
选项:
标志描述
-w, --web
在浏览器中打开仓库
-b, --branch=<branch>
查看指定分支
示例:
bash
undefined

View current repository info

查看当前仓库信息

glab repo view
glab repo view

View specific repo

查看指定仓库

glab repo view gitlab-org/cli
glab repo view gitlab-org/cli

Open in browser

在浏览器中打开

glab repo view --web
glab repo view --web

View specific branch

查看指定分支

glab repo view --branch=develop
undefined
glab repo view --branch=develop
undefined

Create Repository

创建仓库

bash
glab repo create [name] [options]
Options:
FlagDescription
-n, --name=<name>
Repository name
-d, --description=<desc>
Repository description
-g, --group=<group>
Create in specific group/namespace
--public
Make repository public
--private
Make repository private
--internal
Make repository internal
--readme
Initialize with README
-c, --clone
Clone after creation
Examples:
bash
undefined
bash
glab repo create [name] [options]
选项:
标志描述
-n, --name=<name>
仓库名称
-d, --description=<desc>
仓库描述
-g, --group=<group>
在指定组/命名空间下创建
--public
设置仓库为公开
--private
设置仓库为私有
--internal
设置仓库为内部可见
--readme
初始化时添加README文件
-c, --clone
创建后克隆仓库
示例:
bash
undefined

Create repository interactively

交互式创建仓库

glab repo create
glab repo create

Create with name and description

指定名称和描述创建

glab repo create my-project -d "My awesome project"
glab repo create my-project -d "My awesome project"

Create public repo in group

在组内创建公开仓库

glab repo create my-project --group=myteam --public
glab repo create my-project --group=myteam --public

Create and clone

创建并克隆仓库

glab repo create my-project --clone --readme
undefined
glab repo create my-project --clone --readme
undefined

Search Repositories

搜索仓库

bash
glab repo search <query> [options]
Options:
FlagDescription
-P, --per-page=<n>
Results per page
--all
Get all results
Examples:
bash
undefined
bash
glab repo search <query> [options]
选项:
标志描述
-P, --per-page=<n>
每页显示结果数
--all
获取所有结果
示例:
bash
undefined

Search for repos

搜索仓库

glab repo search "cli tools"
glab repo search "cli tools"

Search with more results

搜索更多结果

glab repo search "gitlab" --per-page=50
undefined
glab repo search "gitlab" --per-page=50
undefined

Archive Repository

归档仓库

bash
glab repo archive [repo] [options]
Archives a repository (makes it read-only).
Examples:
bash
undefined
bash
glab repo archive [repo] [options]
归档仓库(设置为只读)。
示例:
bash
undefined

Archive current repo

归档当前仓库

glab repo archive
glab repo archive

Archive specific repo

归档指定仓库

glab repo archive owner/repo
undefined
glab repo archive owner/repo
undefined

Delete Repository

删除仓库

bash
glab repo delete [repo] [options]
Warning: This permanently deletes the repository and all its data!
Options:
FlagDescription
-y, --yes
Skip confirmation prompt
Examples:
bash
undefined
bash
glab repo delete [repo] [options]
警告: 此操作将永久删除仓库及其所有数据!
选项:
标志描述
-y, --yes
跳过确认提示
示例:
bash
undefined

Delete repo (will prompt for confirmation)

删除仓库(将提示确认)

glab repo delete owner/repo
glab repo delete owner/repo

Delete without confirmation (dangerous!)

无需确认直接删除(危险操作!)

glab repo delete owner/repo --yes
undefined
glab repo delete owner/repo --yes
undefined

List Contributors

列出贡献者

bash
glab repo contributors [repo] [options]
Options:
FlagDescription
-P, --per-page=<n>
Results per page
--order=<order>
Sort order: name, email, commits
Examples:
bash
undefined
bash
glab repo contributors [repo] [options]
选项:
标志描述
-P, --per-page=<n>
每页显示结果数
--order=<order>
排序方式:name、email、commits
示例:
bash
undefined

List contributors for current repo

列出当前仓库的贡献者

glab repo contributors
glab repo contributors

List with sorting

按提交数排序列出

glab repo contributors --order=commits
undefined
glab repo contributors --order=commits
undefined

Transfer Repository

转移仓库

bash
glab repo transfer <repo> <new-namespace>
Transfer a repository to another namespace.
Examples:
bash
undefined
bash
glab repo transfer <repo> <new-namespace>
将仓库转移到其他命名空间。
示例:
bash
undefined

Transfer to different group

转移到其他组

glab repo transfer myrepo newgroup
undefined
glab repo transfer myrepo newgroup
undefined

Common Workflows

常见工作流

Workflow 1: Fork and Contribute

工作流1:复刻并贡献代码

bash
undefined
bash
undefined

1. Fork the repository

1. 复刻仓库

glab repo fork upstream/project --clone
glab repo fork upstream/project --clone

2. Add upstream remote

2. 添加上游远程仓库

cd project git remote add upstream https://gitlab.com/upstream/project.git
cd project git remote add upstream https://gitlab.com/upstream/project.git

3. Create feature branch

3. 创建特性分支

git checkout -b feature/my-change
git checkout -b feature/my-change

4. Make changes, commit, push

4. 进行修改、提交、推送

git add . && git commit -m "Add feature" git push -u origin feature/my-change
git add . && git commit -m "Add feature" git push -u origin feature/my-change

5. Create MR to upstream

5. 向上游仓库创建合并请求

glab mr create --target-branch=main
undefined
glab mr create --target-branch=main
undefined

Workflow 2: Batch Clone Team Repos

工作流2:批量克隆团队仓库

bash
undefined
bash
undefined

Clone all non-archived repos from team group

克隆团队组内所有未归档的仓库

glab repo clone -g myteam --archived=false --paginate -p
glab repo clone -g myteam --archived=false --paginate -p

This creates:

将生成以下目录结构:

myteam/

myteam/

repo1/

repo1/

repo2/

repo2/

...

...

undefined
undefined

Workflow 3: Create New Project

工作流3:创建新项目

bash
undefined
bash
undefined

1. Create the repository

1. 创建仓库

glab repo create awesome-project
-d "An awesome new project"
--group=myteam
--readme
--clone
glab repo create awesome-project
-d "An awesome new project"
--group=myteam
--readme
--clone

2. Set up the project

2. 配置项目

cd awesome-project
cd awesome-project

Add initial files...

添加初始文件...

3. View it in browser

3. 在浏览器中查看

glab repo view --web
undefined
glab repo view --web
undefined

Troubleshooting

故障排查

IssueCauseSolution
Authentication failedInvalid/expired tokenRun
glab auth login
Repo not foundInvalid path or no accessCheck repo path and permissions
Clone failedSSH keys not configuredUse HTTPS or configure SSH keys
Cannot forkAlready forked or no permissionCheck existing forks
Cannot deleteNot owner or maintainerRequest owner to delete
问题原因解决方案
认证失败令牌无效/过期运行
glab auth login
重新登录
仓库未找到路径无效或无访问权限检查仓库路径和权限
克隆失败未配置SSH密钥使用HTTPS或配置SSH密钥
无法复刻已复刻或无权限检查现有复刻仓库
无法删除不是所有者或维护者请求所有者删除

Related Documentation

相关文档

  • Safeguards
  • Quick Reference
  • 安全防护
  • 快速参考