SuperAPI AI 工具集

git-ssh-identity

通用与其它

查看项目

更新于 10-16 03:14

技能介绍

用途:在 macOS 上一次性配置好 Git 的“你是谁”——身份信息、SSH 密钥、GitHub 认证、提交签名和常用全局配置默认值。它管理 ~/.gitconfig(通过 git config --global,天然幂等)以及 ~/.ssh/config 中的 GitHub 配置块。不适用于日常 Git 工作流、安装 git/gh 二进制、仓库侧设置(分支保护、密钥)或 Touch ID/FileVault 等安全基线。

主要能力与用法:

  1. 身份与默认项:git config --global user.name / user.email(须向用户询问真实姓名邮箱,不得编造),并设置 init.defaultBranch main、fetch.prune、rebase.autoStash、push.autoSetupRemote、rerere.enabled、merge.conflictstyle zdiff3、diff.colorMoved、branch.sort、column.ui、help.autocorrect 等;编辑器需先确认用户已安装并验证命令存在。
  2. 全局 gitignore:仅追加缺失条目,不截断已有文件,并设置 core.excludesfile。
  3. SSH 密钥与钥匙串:先 ls ~/.ssh/id_* 与 ssh -G github.com 检查现状,绝不覆盖已有密钥;新密钥用 ssh-keygen -t ed25519 并设置口令;在 ~/.ssh/config 写 Host github.com 块(AddKeysToAgent、UseKeychain、IdentityFile),用 /usr/bin/ssh-add --apple-use-keychain 加载。1Password 用户跳过生成密钥。
  4. GitHub 认证:gh auth login(浏览器流程)、gh auth status、ssh -T git@github.com 验证。
  5. SSH 提交签名(可选):gpg.format ssh、user.signingkey、commit.gpgsign、tag.gpgsign,并在 GitHub 以 Signing 类型再次上传同一公钥,否则显示 Unverified;本地验证需 allowed_signers 文件,要求 git ≥ 2.34。
  6. 工作/个人身份分离:用 includeIf gitdir 或 hasconfig:remote.*.url 引入不同配置文件。

限制与注意:口令与令牌不得出现在聊天、文件或命令参数中;已有 user.email/user.name 需先展示并确认再改;追加第二个 Host github.com 块不会覆盖第一个;两个 GitHub 账号需按账号密钥与 Host 别名另行处理;gh 令牌通常存于钥匙串但可能回退到明文 hosts.yml。验证用定向查询而非 --list,避免泄露含凭据的 URL。