1. 同一台电脑有2个github账号?
首先要为每个帐号生成公钥私钥对, 并且设置到 github 里。
修改
~/.ssh/config
, 设置如下
1 | Host unix2dos |
测试:
1 | ssh -T git@unix2dos |
- 要修改仓库的 remote url, 对应
~/.ssh/config
所填写的值. 注意, 要修改 git@后面的这个值
1 | git remote set-url origin git@unix2dos:unix2dos/LevonRecord.git |
一定要设置用户名和邮箱.否则虽然可以提交 commit, 但是不认识你是谁
建议 global 用一个, 其他项目用另外的用户名
1 | git config -l |
2. mac切换用户提交失败的问题
提交总是出现permission denied的问题,用git config –global更新了username和email也不行。
mac os原因是即便更新了username和email,mac在git push时还是会使用历史账号的密码。
解决方法如下:
- 进入Keychain Access (不知道在哪儿的可以command+space查找)
- 在搜索框输入’git’进行查找,将找到的文件删掉,这里保存了历史账号的信息
- 删除之后重新用git config –global更新username和email即可,之后git push会要求你输入username和password
- done!
参考: https://www.zhihu.com/question/23028445/answer/399033488