博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git配置多个账户
阅读量:7048 次
发布时间:2019-06-28

本文共 1319 字,大约阅读时间需要 4 分钟。

hot3.png

前言

公司最近搭建了git服务器,代码要迁移到git服务上。

奈何之前我本机已经绑定了git账户,那么如何再添加一个git账户,并且提交代码时,指定提交到不同的git服务器呢?

Step1 取消之前的git全局设置

# 取消全局账户配置git config --global --unset user.namegit config --global --unset user.email# 增加局部账户配置git config user.name "iron_will"git config user.email "iam_leexk@163.com"

Step2 生成新账户的ssh-key

ssh-keygen -t rsa -C "iam_leexk@163.com"Generating public/private rsa key pair.Enter file in which to save the key (/c/Users/lixk/.ssh/id_rsa): #输入id_rsa_gitosc,会生成两个文件:id_rsa_gitosc,id_rsa_gitosc.pub#在码云上添加SSH公钥id_rsa_gitosc.pub(http://git.oschina.net/profile/sshkeys)

Step3 添加密钥到SSH agent

cd /c/Users/lixk/.ssh/ssh-add id_rsa_gitosc# 如果出现Could not open a connection to your authentication agent的错误,# 执行eval `ssh-agent -s`

Step4 添加config文件

这个时候git客户端已经能与git服务端通过ssh建立连接了,但具体使用哪个账户和哪个git服务进行连接,还需要一些配置,如下

Host gitoscHostName git.oschina.netUser iron_willIdentityFile C:/Users/lixk/.ssh/id_rsa_gitoscHost githubHostName github.comUser lixaingkeIdentityFile C:/Users/lixk/.ssh/id_rsa_github

Step5 使用方法

# 原来的写法git clone git@git.oschina.net:iron_will/myGit.git# 现在的写法git clone git@gitosc:iron_will/myGit.git# 即gitosc和config文件中Host一致,那么实际请求的还是git.oschina.net# 同理,如果你需要克隆github的项目,原来的写法:git clone git@github.com:leexk/ironwill.git# 现在的写法:git clone git@github:leexk/ironwill.git

参考

转载于:https://my.oschina.net/ironwill/blog/796348

你可能感兴趣的文章
最大子序列相关问题
查看>>
Forefront TMG 服务器中如何规划和实现高可用性
查看>>
Exchange Server 2010 故障分享
查看>>
java正则匹配count字符串
查看>>
Exchange2007/2010如何恢复被禁用或者删除的邮箱
查看>>
第五天:Before -- CMD
查看>>
Docker软件安装系列。
查看>>
我的友情链接
查看>>
LEFT JOIN连表时,ON后多条件无效问题
查看>>
[20180423]flashback tablespace与snapshot standby.txt
查看>>
php中禁止单个ip与ip段访问的代码小结
查看>>
LeetCode-330.Patching Array
查看>>
zxing生成二维码转base64 img直接显示 Image对象转Base64码(java)
查看>>
xfire冲突问题解决(maven配置)
查看>>
C#面向对象(三)接口实现多态
查看>>
POJ 3069 Saruman's Army 【贪心】
查看>>
Linux下用Java获取本机IP
查看>>
HTML标签
查看>>
关联规则中的支持度与置信度
查看>>
轻松搭建持续集成工具jenkins
查看>>