用途:让智能体具备访问 GitHub 仓库、PR、Issue 与 CI 的认证能力。
主要能力:先检测环境(git --version、gh --version、gh auth status、git credential.helper),再按决策树选择方式:已认证则直接用 gh;已装 gh 未认证走 gh 登录;未装 gh 走纯 git 方式(无需 sudo)。
使用方式:
- 纯 git + HTTPS 令牌:在 https://github.com/settings/tokens 生成 classic token,勾选 repo、workflow、read:org,设置过期时间;执行 git config --global credential.helper store,再通过 git ls-remote 触发一次认证输入用户名与令牌;也可用 cache --timeout=28800,或把令牌写入 remote URL。最后设置 user.name 与 user.email 并验证。
- SSH 密钥:检查 ~/.ssh/id_*.pub,必要时用 ssh-keygen -t ed25519 生成,把公钥添加到 https://github.com/settings/keys,用 ssh -T git@github.com 测试,并可用 url."git@github.com:".insteadOf 重写 HTTPS 地址。
- gh CLI:gh auth login 交互登录,或使用 OAuth 设备流(curl 请求 device code,用户在 https://github.com/login/device 输入代码,轮询取 token 后经 gh auth login --with-token 与 gh auth setup-git 完成)。无 gh 时可用 curl 配合 GITHUB_TOKEN 调用 API,或从 git 凭据库提取令牌。
限制与注意:Windows PTY 下驱动 gh 登录需用 process(submit) 而非裸 \n,否则会挂起;无头 Linux 上 --with-token 可能因 keyring 阻塞,可用 timeout 20 检测并改为直接写 ~/.config/gh/hosts.yml(chmod 600)。GitHub 已停用密码认证,须用令牌或 SSH。资料未提供具体收费与价格信息。