Skip to main content

GitCode CLI - Command line tool for GitCode

Project description

GitCode CLI

AI 操作指南

Go Version License Release

GitCode 命令行工具,为 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.5.7/gc_0.5.7_amd64.deb

# 安装
sudo dpkg -i gc_0.5.7_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.5.7/gc-0.5.7-1.x86_64.rpm

# 安装
sudo rpm -i gc-0.5.7-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   # Windows

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

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

说明:

  • wheel 会同时安装 gcgitcode 两个命令入口,功能相同。
  • DEB/RPM 包也会同时安装 gcgitcode;Linux 上二者功能相同。
  • Windows PowerShell 预置 gc 作为 Get-Content 别名;如果 gc version 被解析为读取文件,请改用 gitcode versiongc.exe versionpython -m gc_cli version

PyPI(备选)

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

# 安装
pip install gitcode-cli

# Windows PowerShell 中推荐使用 gitcode
gitcode version

预编译二进制文件

从 Release Assets 直接下载对应平台的二进制文件:

平台 文件
Linux x64 gc_<version>_linux_amd64.tar.gz
Linux ARM64 gc_<version>_linux_arm64.tar.gz
macOS Intel gc_<version>_darwin_amd64.tar.gz
macOS Apple Silicon gc_<version>_darwin_arm64.tar.gz
Windows x64 gc_<version>_windows_amd64.zip

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

解压后将二进制文件放到 PATH 目录:

# Linux/macOS
tar -xzf gc_*.tar.gz
mv gc ~/.local/bin/

# Windows
# 解压 zip 文件后,将 gc.exe 放到 PATH 目录

规划中的安装方式

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

  • Homebrew (macOS/Linux)
  • Scoop (Windows)
  • Docker 镜像

快速开始

认证

方式一:设置环境变量(推荐)

# 设置 Token 环境变量
export GC_TOKEN="your_gitcode_token"

# 或使用备用变量名
export GITCODE_TOKEN="your_gitcode_token"

# 添加到 shell 配置文件(永久生效)
echo 'export GC_TOKEN="your_gitcode_token"' >> ~/.bashrc
source ~/.bashrc

方式二:交互式登录

# 交互式登录(需输入 Token)
gc auth login

# 非交互登录(从 stdin 读取 Token)
echo "YOUR_TOKEN" | gc auth login --with-token

当前版本认证优先级:

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

说明:

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

获取 Token:

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

验证认证:

# 查看认证状态
gc auth status

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

输出格式

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

# 结构化输出
gc issue list -R owner/repo --json
gc issue list -R owner/repo --format json

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

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

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

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

常见任务入口

最常用的起步命令:

# 查看仓库
gc repo view

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

# 列出 Issues
gc issue list --state open

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

# 查看认证状态
gc 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 使用 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 团队的开源贡献。

相关链接

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitcode_cli-0.5.7.tar.gz (16.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitcode_cli-0.5.7-py3-none-any.whl (16.2 MB view details)

Uploaded Python 3

File details

Details for the file gitcode_cli-0.5.7.tar.gz.

File metadata

  • Download URL: gitcode_cli-0.5.7.tar.gz
  • Upload date:
  • Size: 16.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for gitcode_cli-0.5.7.tar.gz
Algorithm Hash digest
SHA256 60ee8259d6a0c968239dbc31803343f6315fdd9795c5b4d6da77246da093a559
MD5 8e0dd94a39a9f4fb0c445d179348d98f
BLAKE2b-256 18bf9e921c51b82c4781a21cf8651043c231e519faa9ac9330a974647bd9b473

See more details on using hashes here.

File details

Details for the file gitcode_cli-0.5.7-py3-none-any.whl.

File metadata

  • Download URL: gitcode_cli-0.5.7-py3-none-any.whl
  • Upload date:
  • Size: 16.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for gitcode_cli-0.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 030b16abf12bff6d1b8e1c597b560076c01a96f68f7b760fd55ef3e70efff72c
MD5 6c7d4326d7076bb03a50dee63d4c4881
BLAKE2b-256 d2b83f91ea2e0b319bd48279a9008eb6de60d61928bd7ba15cbd3f14e0009eed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page