侧边栏壁纸
博主头像
集智芬享

The only way to be truly heroic is to know life's truths and still love it.

  • 累计撰写 13 篇文章
  • 累计创建 17 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Git系列教程-Windows上GitBash配置多个Git账号

Administrator
2025-05-27 / 0 评论 / 0 点赞 / 7 阅读 / 0 字
温馨提示:
本文最后更新于2025-05-27,若内容或图片失效,请留言反馈。 部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

主要是利用SSH密钥加上修改ssh配置文件来管理不同的Git账号

1.生成Git账号密钥

我们需要为每一个Git账号生成独立的SSH密钥,id_rsa_account1不同账号用不同的名称(例如:id_rsa_account1、id_rsa_account2、、、):

 ssh-keygen -t rsa -b 4096 -C "你的GitHub账户邮箱" -f ~/.ssh/id_rsa_account1

2.修改SSH配置文件

编辑Windows用户文件夹目录下文件,没有就创建一个:~/.ssh/config,添加不同账号的配置信息: image-20250527202134936

用Vscode或者记事本打开都行,修改后保存。

 # Account 1
 Host github.com-account1
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_account1
 # Account 2
 Host github.com-account2
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_account2
 # Account 2
 Host github.com-account3
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_account3

配置文件权限

 chmod 600 ~/.ssh/config

3.将公钥添加到Github

查看公钥文件,全选复制

 cat ~/.ssh/id_rsa_account1.pub

进入设置页面,https://github.com/settings/keys,点击 New SSH key,粘贴公钥并保存。

image-20250527203227798

测试SSH连接

 ssh -T git@github.com-account1

成功之后会看到类似:Hi xxx, You are successfully authenticated...

克隆仓库

举例,通常我们是git clone git@github.com:Significant-Gravitas/AutoGPT.git,这里我们就修改成git clone git@github.com-account1:Significant-Gravitas/AutoGPT.git

image-20250527203620848

为单个仓库配置git用户

局部配置仓库的用户名和邮箱,每个仓库直接互不影响。

 cd /path/to/repo
 git config user.name "你的GitHub用户名"
 git config user.email "你的GitHub用户邮箱"


0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin
  3. QQ打赏

    qrcode qq
广告 广告

评论区