【經驗】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....

html

相關文章
相關標籤/搜索