cnb-rs auth setup-git
cnb-rs auth setup-git [-H <host>] [-f]配置 git credential helper 使用 cnb-rs token,让 git push / git clone https://<host>/... 自动用 cnb-rs 已保存的 token,免去每次手动输入。对齐 gh auth setup-git。
行为
向 ~/.gitconfig(全局)写入:
ini
[credential "https://cnb.cool"]
helper =
helper = !"<absolute path to cnb-rs>" auth gitcredential第一行空 helper = 清空之前的 helper 链,避免与系统默认凭证冲突(gh CLI 同样做法)。之后 git 在需要 https://cnb.cool 凭证时会通过 git credential 子系统调用 cnb-rs 的 gitcredential 命令拿 token。
为什么 -H 而不是 -h
gh 端用 -h/--hostname,但 clap derive 默认 -h 是 --help 的 short,强占冲突;cnb-rs 端改用大写 -H 避免与 clap auto-generated -h/--help 冲突。
选项
-H, --hostname <HOST>: 指定 hostname(默认当前--domain值,默认cnb.cool)-f, --force: 强制覆盖已有 helper 配置(默认有 helper 时拒绝并列出现有值,让用户决定)
继承的全局选项:
--domain <DOMAIN>: 指定目标域名(默认:cnb.cool),与-H二选一
前置条件
- 系统需安装
git - 当前用户对
~/.gitconfig(或对应平台的全局 git config)有写权限
示例
bash
# 默认配置 cnb.cool 的 credential helper
$ cnb-rs auth setup-git
✓ 已配置 git credential helper:credential.https://cnb.cool.helper
现在 git clone / push cnb.cool 上的仓库时会自动使用 cnb-rs 的 token
# 指定其他 hostname
$ cnb-rs auth setup-git -H example.com
# 已配置过,拒绝覆盖
$ cnb-rs auth setup-git
credential.https://cnb.cool.helper 已存在 1 个配置:
manager-core
错误: 加 -f/--force 覆盖,或先手动 git config --global --unset credential.https://cnb.cool.helper
# 强制覆盖
$ cnb-rs auth setup-git --force
# 撤销
$ git config --global --unset-all credential.https://cnb.cool.helper撤销
bash
git config --global --unset-all credential.https://cnb.cool.helper或直接编辑 ~/.gitconfig 删除对应 [credential "https://cnb.cool"] 段。
另请参阅
- cnb-rs auth
- cnb-rs auth gitcredential — setup-git 写入的 helper 实际调用的命令
- cnb-rs auth login — 必须先 login 才有 token 可用
- git credentials — git 官方 credential helper 协议文档