cli

module
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT

README

GitCode CLI

AI 操作指南

Go Version License Release

GitCode CLI 把仓库、Issue、PR、Release 和 Actions 带回终端,让开发者减少页面切换,也让脚本与 AI 获得结构化、可审计、带安全边界的 GitCode 执行入口。

快速了解核心价值与应用场景,并在五分钟内开始使用

文档导航

按角色建议从以下入口开始:

角色 入口
使用者 docs/README.md
开发者 spec/README.md
Codex / 代理 AGENTS.md
Claude CLAUDE.md

主要文档:

安装

从源码构建

前置要求:

  • Go 1.22+
# 克隆仓库(需要 git clone 才能获取版本信息)
git clone https://gitcode.com/gitcode-cli/cli.git
cd cli

# 方式一:使用 go build(推荐)
go build -o gc ./cmd/gc
# 安装
mkdir -p ~/.local/bin
mv gc ~/.local/bin/

# 方式二:使用 make build(带完整版本标签)
make build
# 安装
mkdir -p ~/.local/bin
mv bin/gc ~/.local/bin/

# 添加到 PATH
export PATH="$HOME/.local/bin:$PATH"

说明:

  • go builddebug.ReadBuildInfo() 自动获取 git commit 和构建时间(需要 git clone 源码)。
  • make build 使用 -ldflags 注入完整版本标签(如 v0.3.11-38-g1128f2b)。
Linux 包管理器

DEB (Debian/Ubuntu):

# 从 Releases 下载 .deb 包
wget https://gitcode.com/gitcode-cli/cli/releases/download/v0.10.3/gc_0.10.3_amd64.deb

# 安装
sudo dpkg -i gc_0.10.3_amd64.deb

DEB/RPM packages install both gc and gitcode; on Linux they are equivalent.

RPM (RHEL/CentOS/Fedora):

# 从 Releases 下载 .rpm 包
wget https://gitcode.com/gitcode-cli/cli/releases/download/v0.10.3/gc-0.10.3-1.x86_64.rpm

# 安装
sudo rpm -i gc-0.10.3-1.x86_64.rpm

DEB/RPM packages install both gc and gitcode; on Linux they are equivalent.

Wheel 包(跨平台,推荐)

从 Release 归档下载 wheel 包安装,内置全平台二进制(Linux x64/ARM、macOS Intel/Apple Silicon、Windows x64):

# 创建虚拟环境
python3 -m venv .venv
source .venv/bin/activate  # Linux/macOS
# .\.venv\Scripts\Activate.ps1  # Windows PowerShell

# 安装(一行命令)
pip install https://gitcode.com/gitcode-cli/cli/releases/download/v0.10.3/gitcode_cli-0.10.3-py3-none-any.whl

# Windows PowerShell 中推荐使用 gitcode,避免 gc 被内置 Get-Content 别名覆盖
gitcode version

说明:

  • wheel 会同时安装 gcgitcode 两个命令入口,功能相同。
  • DEB/RPM 包也会同时安装 gcgitcode;Linux 上二者功能相同。
  • Windows 使用 py -m pip install --user ... 时,脚本会安装到 Python user scheme 的 Scripts 目录。请运行 py -c "import os, sysconfig; print(sysconfig.get_path('scripts', os.name + '_user'))" 获取准确路径,将其加入用户 PATH 后重新打开终端;配置前可直接运行 py -m gc_cli version
  • Windows PowerShell 预置 gc 作为 Get-Content 别名;如果 gc version 被解析为读取文件,请改用 gitcode versiongc.exe versionpy -m gc_cli version
  • Windows PowerShell 中通过 --body-file - / --comment-file - 管道传入中文或其他非 ASCII 正文时,推荐使用 UTF-8 文件;如果必须直接管道,先设置 $OutputEncoding = [System.Text.UTF8Encoding]::new($false)。CLI 会拦截疑似已被 PowerShell 损坏成 ??? 的输入并提示正确用法。
Set-Content -Path body.md -Value "中文正文" -Encoding UTF8
gitcode issue create -R owner/repo --title "标题" --body-file body.md
PyPI(备选)

PyPI 可能晚于 GitCode Release 同步。固定目标版本可避免静默安装旧版本;目标版本暂不可用时,请使用上方 Release wheel。

# 创建虚拟环境
python3 -m venv .venv
source .venv/bin/activate  # Linux/macOS
# .\.venv\Scripts\Activate.ps1  # Windows PowerShell

# 固定版本安装,避免 PyPI 尚未同步时安装旧版本
python -m pip install -i https://pypi.org/simple/ gitcode-cli==0.10.3

# Windows PowerShell 中推荐使用 gitcode
gitcode version
Linux 二进制文件

从 Release Assets 直接下载 Linux 二进制文件:

平台 文件
Linux x64 gc_linux_amd64
Linux ARM64 gc_linux_arm64

下载地址: https://gitcode.com/gitcode-cli/cli/releases

下载后赋予可执行权限,并放到 PATH 目录:

chmod +x gc_linux_amd64
mv gc_linux_amd64 ~/.local/bin/gc
gc version

Windows 和 macOS 用户建议使用上方 wheel 包;wheel 内置 Linux、macOS 和 Windows 二进制,并同时提供 gcgitcode 两个命令入口。

Docker 镜像

仓库已提供 Dockerfiledocker-compose.yml 和 Makefile 目标:

# 构建并运行
make docker-build
make docker-run

# 或使用 docker compose
docker compose up gc

认证 Token 通过环境变量传入。请在交互终端中静默读取,避免 Token 值进入 shell history:

read -rsp "GitCode token: " GC_TOKEN
export GC_TOKEN
make docker-run
unset GC_TOKEN

更多用法参见 Makefile 和 docker-compose.yml

Homebrew (macOS/Linux)
brew install gitcode-cli/homebrew-tap/gc

更新到最新版本:

brew upgrade gc

shell 补全(bash/zsh/fish)随安装自动配置,无需额外操作。

npm (跨平台)

一行 bootstrap(无需全局 npm 安装,自动装二进制 + 补全):

npx @gitcode-cli/cli@latest install

或全局安装:

npm install -g @gitcode-cli/cli
gc version

包内置 Linux/macOS/Windows 多平台二进制;shell 补全(bash/zsh/fish)由 install 子命令自动配置。

规划中的安装方式

以下安装方式正在开发中:

  • Scoop (Windows)

快速开始

认证

以下示例使用安装包提供的 gitcode 入口;从源码构建或使用独立二进制时,请将命令名改为 gc

方式一:打开令牌页面并登录

gitcode auth login --web

当前 --web 会打开 GitCode 的新建访问令牌页面,生成令牌后仍需回到终端粘贴。当前版本不会隐藏输入,因此必须由用户本人在私有、未录制且不由 AI 控制的本地终端中执行。

方式二:交互式 Token 登录

gitcode auth login

浏览器不可用时,可在同样受控的本地交互终端中输入 Token。不要把 Token 值直接写进命令、shell history 或配置脚本。CI 场景应通过平台 Secret 注入 GC_TOKENGITCODE_TOKEN

当前版本认证优先级:

  1. GC_TOKEN
  2. GITCODE_TOKEN
  3. 本地登录配置

说明:

  • gc auth login 会将认证信息持久化到本地配置目录
  • 如果设置了环境变量,环境变量始终覆盖本地配置
  • gc auth logout 只清理本地配置,不会自动取消环境变量
  • 详细规则见 docs/AUTH.md

获取 Token:

  1. 登录 GitCode
  2. 进入 个人设置 -> 访问令牌
  3. 点击“新建访问令牌”,选择所需权限
  4. 复制生成的 Token

验证认证:

# 查看认证状态
gitcode auth status

详细命令行为和完整示例请查看 docs/COMMANDS.md

输出格式

gitcode 的只读命令继续以文本输出为默认体验,同时为脚本和代理保留稳定的结构化入口。

# 结构化输出
gitcode issue list -R owner/repo --json
gitcode issue list -R owner/repo --format json
gitcode repo log -R owner/repo --file README.md --branch main --json
gitcode pr list -R owner/repo --paginate --per-page 100 --json

# 常规文本与表格
gitcode issue list -R owner/repo --format simple
gitcode issue list -R owner/repo --format table

# 时间格式切换
gitcode issue list -R owner/repo --time-format absolute
gitcode issue list -R owner/repo --time-format relative

# 自定义模板输出
gitcode issue list -R owner/repo --template '{{range .}}#{{.Number}} {{.Title}}{{"\n"}}{{end}}'

# typed command 尚未覆盖的 API,可用 gitcode api 读取原始响应
gitcode api repos/owner/repo

issue viewpr view 的文本详情展示也会保持稳定布局,而 --json 仍然是面向机器调用的首选入口。

常见任务入口

最常用的起步命令:

# 查看仓库
gitcode repo view

# 查看文件提交历史
gitcode repo log -R owner/repo --file README.md --branch main

# 创建 Issue
gitcode issue create --title "Bug report" --body "Description"

# 列出 Issues
gitcode issue list --state open

# 创建 PR
gitcode pr create --title "New feature" --base main

# 按提交信息反查 PR
gitcode pr list -R owner/repo --commit-message "fix login"

# 提交前检查 pre-commit 配置与本地环境
gitcode precommit check

# 查看流水线运行记录
gitcode actions run list -R owner/repo --status FAILED

# 查看流水线运行详情
gitcode actions run view <run-id> -R owner/repo

# 列出流水线运行的 jobs
gitcode actions job list <run-id> -R owner/repo

# 查看工作流 job 详情
gitcode actions job view <run-id> <job-id> -R owner/repo

# 下载 job 日志归档
gitcode actions job log <run-id> <job-id> -R owner/repo --output job-log.zip

# 列出仓库 artifacts
gitcode actions artifact list -R owner/repo

# 查看 artifact 详情
gitcode actions artifact view <artifact-id> -R owner/repo

# 下载 artifact
gitcode actions artifact download <artifact-id> -R owner/repo --output artifact.zip

# 删除 artifact
gitcode actions artifact delete <artifact-id> -R owner/repo --yes

# 调用 GitCode API 原始响应
gitcode api repos/owner/repo

# 查看认证状态
gitcode auth status

完整命令说明、参数细节、平台限制和更多示例,请直接查看:

Shell 补全

# Bash
gc completion bash > /etc/bash_completion.d/gc
source ~/.bashrc

# Zsh
gc completion zsh > "${fpath[1]}/_gc"
source ~/.zshrc

# Fish
gc completion fish > ~/.config/fish/completions/gc.fish
source ~/.config/fish/config.fish

项目定位

当前仓库已经建立:

如果你要看完整规范、构建与发布规则、质量门禁和 AI 协作边界,请直接进入对应入口,不要仅依赖本 README。

补充说明:

  • docs/AI-GUIDE.md 只服务外部项目通过 AI 使用 gitcode(或源码构建的 gc
  • gitcode-cli 仓库内部 AI 开发请看 AGENTS.mdCLAUDE.mdspec/workflows/ai-local-development-workflow.md
  • issues-plan/PROGRESS.md 只作为阶段说明,不作为单个 issue / PR 的实时事实依据

开发

# 克隆仓库
git clone https://gitcode.com/gitcode-cli/cli.git
cd gitcode-cli

# 安装依赖
make deps

# 构建
make build

# 运行测试
make test

# 代码检查
make lint

# 运行
make run

贡献

欢迎贡献代码。开始前请查看 贡献指南spec/README.md

许可证

MIT License

致谢

本项目参考了 GitHub CLI 的设计与实现,感谢 GitHub 团队的开源贡献。

相关链接

Directories

Path Synopsis
Package api provides GitCode API client
Package api provides GitCode API client
cmd
gc command
Package main is the entry point for gitcode-cli
Package main is the entry point for gitcode-cli
Package git provides Git operations for gitcode-cli
Package git provides Git operations for gitcode-cli
pkg
browser
Package browser provides utilities for opening URLs in a web browser
Package browser provides utilities for opening URLs in a web browser
cmd/actions
Package actions implements the actions command.
Package actions implements the actions command.
cmd/actions/artifact
Package artifact implements the actions artifact command.
Package artifact implements the actions artifact command.
cmd/actions/artifact/delete
Package delete implements the actions artifact delete command.
Package delete implements the actions artifact delete command.
cmd/actions/artifact/download
Package download implements the actions artifact download command.
Package download implements the actions artifact download command.
cmd/actions/artifact/list
Package list implements the actions artifact list command.
Package list implements the actions artifact list command.
cmd/actions/artifact/view
Package view implements the actions artifact view command.
Package view implements the actions artifact view command.
cmd/actions/job
Package job implements the actions job command.
Package job implements the actions job command.
cmd/actions/job/list
Package list implements the actions job list command.
Package list implements the actions job list command.
cmd/actions/job/log
Package log implements the actions job log command.
Package log implements the actions job log command.
cmd/actions/job/view
Package view implements the actions job view command.
Package view implements the actions job view command.
cmd/actions/run
Package run implements the actions run command.
Package run implements the actions run command.
cmd/actions/run/list
Package list implements the actions run list command.
Package list implements the actions run list command.
cmd/actions/run/view
Package view implements the actions run view command.
Package view implements the actions run view command.
cmd/actions/runner
Package runner implements the actions runner command.
Package runner implements the actions runner command.
cmd/actions/runner-group
Package runnergroup implements the actions runner-group command.
Package runnergroup implements the actions runner-group command.
cmd/actions/runner-group/list
Package list implements the actions runner-group list command.
Package list implements the actions runner-group list command.
cmd/actions/runner-group/runner
Package runner implements the actions runner-group runner command.
Package runner implements the actions runner-group runner command.
cmd/actions/runner-group/runner-set
Package runnerset implements the actions runner-group runner-set command.
Package runnerset implements the actions runner-group runner-set command.
cmd/actions/runner-group/runner-set/list
Package list implements the actions runner-group runner-set list command.
Package list implements the actions runner-group runner-set list command.
cmd/actions/runner-group/runner/list
Package list implements the actions runner-group runner list command.
Package list implements the actions runner-group runner list command.
cmd/actions/runner-group/shared-namespace
Package sharednamespace implements the actions runner-group shared-namespace command.
Package sharednamespace implements the actions runner-group shared-namespace command.
cmd/actions/runner-group/shared-namespace/list
Package list implements the actions runner-group shared-namespace list command.
Package list implements the actions runner-group shared-namespace list command.
cmd/actions/runner-group/view
Package view implements the actions runner-group view command.
Package view implements the actions runner-group view command.
cmd/actions/runner-set
Package runnerset implements the actions runner-set command.
Package runnerset implements the actions runner-set command.
cmd/actions/runner-set/list
Package list implements the actions runner-set list command.
Package list implements the actions runner-set list command.
cmd/actions/runner-set/shared-runner-sets
Package sharedrunnersets implements the actions runner-set shared-runner-sets command.
Package sharedrunnersets implements the actions runner-set shared-runner-sets command.
cmd/actions/runner/list
Package list implements the actions runner list command.
Package list implements the actions runner list command.
cmd/actions/runner/shared-runners
Package sharedrunners implements the actions runner shared-runners command.
Package sharedrunners implements the actions runner shared-runners command.
cmd/api
Package api implements the generic api command.
Package api implements the generic api command.
cmd/auth
Package auth implements authentication commands
Package auth implements authentication commands
cmd/auth/login
Package login implements the auth login command
Package login implements the auth login command
cmd/auth/logout
Package logout implements the auth logout command
Package logout implements the auth logout command
cmd/auth/status
Package status implements the auth status command
Package status implements the auth status command
cmd/auth/token
Package token implements the auth token command
Package token implements the auth token command
cmd/commit
Package commit implements the commit command
Package commit implements the commit command
cmd/commit/comments
Package comments implements the commit comments command
Package comments implements the commit comments command
cmd/commit/comments/create
Package create implements the commit comments create command
Package create implements the commit comments create command
cmd/commit/comments/edit
Package edit implements the commit comments edit command
Package edit implements the commit comments edit command
cmd/commit/comments/list
Package list implements the commit comments list command
Package list implements the commit comments list command
cmd/commit/comments/listbysha
Package listbysha implements the commit comments list-by-sha command
Package listbysha implements the commit comments list-by-sha command
cmd/commit/comments/view
Package view implements the commit comments view command
Package view implements the commit comments view command
cmd/commit/diff
Package diff implements the commit diff command
Package diff implements the commit diff command
cmd/commit/patch
Package patch implements the commit patch command
Package patch implements the commit patch command
cmd/commit/view
Package view implements the commit view command
Package view implements the commit view command
cmd/help
Package help implements the help command with search and discovery features.
Package help implements the help command with search and discovery features.
cmd/issue
Package issue implements the issue command
Package issue implements the issue command
cmd/issue/close
Package close implements the issue close command
Package close implements the issue close command
cmd/issue/comment
Package comment implements the issue comment command
Package comment implements the issue comment command
cmd/issue/comment/edit
Package edit implements the issue comment edit command.
Package edit implements the issue comment edit command.
cmd/issue/comments
Package comments implements the issue comments command.
Package comments implements the issue comments command.
cmd/issue/create
Package create implements the issue create command
Package create implements the issue create command
cmd/issue/edit
Package edit implements the issue edit command
Package edit implements the issue edit command
cmd/issue/label
Package label implements the issue label command
Package label implements the issue label command
cmd/issue/list
Package list implements the issue list command
Package list implements the issue list command
cmd/issue/prs
Package prs implements the issue prs command
Package prs implements the issue prs command
cmd/issue/relations
Package relations implements the issue relations command.
Package relations implements the issue relations command.
cmd/issue/reopen
Package reopen implements the issue reopen command
Package reopen implements the issue reopen command
cmd/issue/view
Package view implements the issue view command
Package view implements the issue view command
cmd/label
Package label implements the label command
Package label implements the label command
cmd/label/create
Package create implements the label create command
Package create implements the label create command
cmd/label/delete
Package delete implements the label delete command
Package delete implements the label delete command
cmd/label/list
Package list implements the label list command
Package list implements the label list command
cmd/lark
Package lark implements the lark command group, a subprocess bridge to the official Feishu/Lark CLI (lark-cli).
Package lark implements the lark command group, a subprocess bridge to the official Feishu/Lark CLI (lark-cli).
cmd/milestone
Package milestone implements the milestone command
Package milestone implements the milestone command
cmd/milestone/create
Package create implements the milestone create command
Package create implements the milestone create command
cmd/milestone/delete
Package delete implements the milestone delete command
Package delete implements the milestone delete command
cmd/milestone/edit
Package edit implements the milestone edit command
Package edit implements the milestone edit command
cmd/milestone/list
Package list implements the milestone list command
Package list implements the milestone list command
cmd/milestone/view
Package view implements the milestone view command
Package view implements the milestone view command
cmd/pr
Package pr implements the pr command
Package pr implements the pr command
cmd/pr/checkout
Package checkout implements the pr checkout command
Package checkout implements the pr checkout command
cmd/pr/close
Package close implements the pr close command
Package close implements the pr close command
cmd/pr/comment
Package comment implements the PR comment command
Package comment implements the PR comment command
cmd/pr/comment/delete
Package delete implements the PR comment delete command
Package delete implements the PR comment delete command
cmd/pr/comment/edit
Package edit implements the PR comment edit command
Package edit implements the PR comment edit command
cmd/pr/comment/resolve
Package resolve implements the PR comment resolve/unresolve commands
Package resolve implements the PR comment resolve/unresolve commands
cmd/pr/comments
Package comments implements the pr comments command
Package comments implements the pr comments command
cmd/pr/create
Package create implements the pr create command
Package create implements the pr create command
cmd/pr/diff
Package diff implements the pr diff command
Package diff implements the pr diff command
cmd/pr/edit
Package edit implements the pr edit command
Package edit implements the pr edit command
cmd/pr/issues
Package issues implements the pr issues command
Package issues implements the pr issues command
cmd/pr/label
Package label implements the pr label command
Package label implements the pr label command
cmd/pr/list
Package list implements the pr list command
Package list implements the pr list command
cmd/pr/merge
Package merge implements the pr merge command
Package merge implements the pr merge command
cmd/pr/ready
Package ready implements the pr ready command
Package ready implements the pr ready command
cmd/pr/reopen
Package reopen implements the pr reopen command
Package reopen implements the pr reopen command
cmd/pr/reply
Package reply implements the pr reply command
Package reply implements the pr reply command
cmd/pr/review
Package review implements the pr review command
Package review implements the pr review command
cmd/pr/sync
Package sync implements the pr sync command.
Package sync implements the pr sync command.
cmd/pr/test
Package test implements the pr test command
Package test implements the pr test command
cmd/pr/view
Package view implements the pr view command
Package view implements the pr view command
cmd/precommit
Package precommit implements the precommit command group.
Package precommit implements the precommit command group.
cmd/precommit/check
Package check implements the `precommit check` command.
Package check implements the `precommit check` command.
cmd/release
Package release implements the release command
Package release implements the release command
cmd/release/create
Package create implements the release create command
Package create implements the release create command
cmd/release/delete
Package delete implements the release delete command
Package delete implements the release delete command
cmd/release/download
Package download implements the release download command
Package download implements the release download command
cmd/release/edit
Package edit implements the release edit command
Package edit implements the release edit command
cmd/release/list
Package list implements the release list command
Package list implements the release list command
cmd/release/upload
Package upload implements the release upload command
Package upload implements the release upload command
cmd/release/view
Package view implements the release view command
Package view implements the release view command
cmd/repo
Package repo implements repository commands
Package repo implements repository commands
cmd/repo/branch
Package branch implements the repo branch command
Package branch implements the repo branch command
cmd/repo/clone
Package clone implements the repo clone command
Package clone implements the repo clone command
cmd/repo/create
Package create implements the repo create command
Package create implements the repo create command
cmd/repo/delete
Package delete implements the repo delete command
Package delete implements the repo delete command
cmd/repo/fork
Package fork implements the repo fork command
Package fork implements the repo fork command
cmd/repo/list
Package list implements the repo list command
Package list implements the repo list command
cmd/repo/log
Package log implements the repo log command.
Package log implements the repo log command.
cmd/repo/stats
Package stats implements the repo stats command
Package stats implements the repo stats command
cmd/repo/sync
Package sync implements the repo sync command.
Package sync implements the repo sync command.
cmd/repo/view
Package view implements the repo view command
Package view implements the repo view command
cmd/root
Package root implements the root command for gc.
Package root implements the root command for gc.
cmd/schema
Package schema exposes machine-readable command metadata.
Package schema exposes machine-readable command metadata.
cmd/version
Package version implements the version command
Package version implements the version command
cmdutil
Package cmdutil provides utilities for command implementation
Package cmdutil provides utilities for command implementation
config
Package config provides configuration management for gitcode-cli
Package config provides configuration management for gitcode-cli
iostreams
Package iostreams provides input/output stream management
Package iostreams provides input/output stream management
larkcli
Package larkcli provides a subprocess bridge to the official Feishu/Lark CLI tool (lark-cli).
Package larkcli provides a subprocess bridge to the official Feishu/Lark CLI tool (lark-cli).
precommit
Package precommit detects and manages pre-commit configuration and environment.
Package precommit detects and manages pre-commit configuration and environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL