【经验】github

1.pull免密码
git config --global credential.helper store

2.git多账号并存
先参考http://www.cnblogs.com/BeginMan/p/3548139.html

创建私钥
$ cd ~/.ssh
$ ssh-keygen -t rsa -C 'xx@qq.com'

设置名称,默认为id_rsa。注意不能与已有的文件重复
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_personal

接下来的流程参考
将新密钥添加到SSH agent中:
ssh-add ~/.ssh/id_rsa_personal

假如提示Could not open a connection to your authentication agent,则根据http://unix.stackexchange.com/questions/48863/ssh-add-complains-could-not-open-a-connection-to-your-authentication-agent/48868#48868 中所说,执行:
eval "$(ssh-agent)"
再执行ssh-add ~/.ssh/id_rsa_personal即可。

接下来进入~/.ssh目录,打开config文件,如果没有就如下创建:
touch config

然后是config的设置。这里不要看上面的网站,可以参考先参考http://www.tuicool.com/articles/7z67ny2

而我的写法是:
#这里教程里写成git.oschina.net,我在前面加了个"work."
#因为有时候就是不行,提示Access denied。
Host work.git.oschina.net
HostName git.oschina.net
User git
IdentityFile C:/Users/admin/.ssh/id_rsa
#IdentitiesOnly yes

#注意两个Host不能一样
Host personal.git.oschina.net
#这里的意思大概是如果使用了一个地址,
#而地址匹配了Host中设的"personal.git.oschina.net",
#则这一段将被替换为HostName所设的"git.oschina.net"
HostName git.oschina.net
User git
IdentityFile C:/Users/admin/.ssh/id_rsa_personal
#IdentitiesOnly yes

这样设置之后,如果是直接使用git.oschina.net,可能会以默认的id_rsa(即上述的第一段)去处理。

设置了host后,已经存在的项目可能需要设置一下。
#删除掉值为git@work.git.oschina.net....的origin仓库地址
git remote remove origin
#增加有前缀的仓库地址
git remote add origin git@work.git.oschina.net....

posted @ 2017-03-06 19:02  FranQ  阅读(81)  评论(0编辑  收藏  举报