Windows机器上配置两个git账号
Windows机器上配置两个git账号
测试机器windows 8.1
情景:
有两个GitHub路径和账号,分别是:
(1)路径:git@hostname.com:aaa/bbb.git
账号:zhangsan
(2)路径:git@github.com:rainbow-tan/rainbow.git
账号:rainbow-tan
需求:
需要根据不同账号下载对应git资源和更新(pull,push)
一个账号用于公司开发
一个账号用于自己开发
方法:
1.机器安装Git客户端
2.启动Git Bash
3.生成两个ssh key秘钥
ssh-keygen -t rsa -C 'xxxxx@company.com' -f ~/.ssh/gitee_id_rsa
ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/github_id_rsa
4.拷贝本机C盘用户目录下的gitee_id_rsa.pub内容到git@hostname.com:aaa/bbb.git的ssh key中
拷贝本机C盘用户目录下的github_id_rsa.pub内容到git@github.com:rainbow-tan/rainbow.git中
5.在C盘用户目录下添加文件,文件名为config(注意没有后缀.txt),文件内容为:
# gitee
Host hostname.com
HostName hostname.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
注意:
这里的 xxxxx@xxxxx.com 只是生成的 sshkey 的名称,并不约束或要求具体命名为某个邮箱。
Host和HostName需要写GitHub路径的域名,即hostname.com和github.com
IdentityFile写~/.ssh/比较好,而不是直接写绝对路径(如C:\Users\yangxinhang\.ssh\github_id_rsa)
参考链接:https://gitee.com/help/articles/4229

浙公网安备 33010602011771号