git-电脑如何管理多个代码仓库

122 阅读1分钟

针对mac电脑进行操作指导

问题描述:当一个电脑既要管理 gitlab、github、极狐等多个代码账户时,如何配置公钥、私钥

误解1

无论是gitlab github gitee等 生成钥匙的命令是同一个

ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa_gitee_gitlab

无解2

如果邮箱相同的情况下,多个平台是可以使用同一个公钥、私钥

误解3

即使https也是可以提交代码和拉去代码的

如下命令

要在您的 .ssh/config 文件中添加极狐(Gitee)的密钥,您可以按照下面的步骤进行:

  1. 生成一个新的 SSH 密钥(如果您还没有为极狐生成一个密钥):
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

生成密钥时,您可以指定一个文件名,例如 id_rsa_gitee

  1. 将生成的密钥添加到 ~/.ssh/config 文件中: 编辑您的 ~/.ssh/config 文件,添加以下内容:
# 极狐(Gitee)密钥
Host gitee.com
    HostName gitee.com
    User git
    IdentityFile ~/.ssh/id_rsa_gitee # 极狐(Gitee)密钥路径
  1. 将生成的公钥添加到极狐(Gitee)账户中

复制生成的公钥内容(通常位于 ~/.ssh/id_rsa_gitee.pub)并将其添加到您的极狐(Gitee)账户的 SSH 密钥设置中。

例如,最终的 ~/.ssh/config 文件可能看起来像这样:

# 默认 GitLab 密钥
Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa

# GitHub 密钥
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_key

# 极狐(Gitee)密钥
Host gitee.com
    HostName gitee.com
    User git
    IdentityFile ~/.ssh/id_rsa_gitee

完成这些步骤后,您就可以通过 SSH 连接到极狐(Gitee)并使用您添加的密钥进行身份验证了。