先假設我有兩個帳號,一個是github上的,一個是公司gitlab上面的。先爲不一樣的帳號生成不一樣的ssh-keygit
ssh-keygen -t rsa -f ~/.ssh/id_rsa_work -c xxx@gmail.com
而後根據提示連續回車便可在~/.ssh目錄下獲得id_rsa_work和id_rsa_work.pub兩個文件,id_rsa_work.pub文件裏存放的就是咱們要使用的keygithub
ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -c xxx@gmail.com
而後根據提示連續回車便可在~/.ssh目錄下獲得id_rsa_github和id_rsa_github.pub兩個文件,id_rsa_gthub.pub文件裏存放的就是咱們要使用的key服務器
把id_rsa_xxx.pub中的key添加到github或gitlab上,這一步在github或gitlab上都有幫助,再也不贅述app
編輯 ~/.ssh/config
,設定不一樣的git 服務器對應不一樣的keyssh
# Default github user(first@mail.com),注意User項直接填git,不用填在github的用戶名 Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_github # second user(second@mail.com) # 建一個gitlab別名,新建的賬號使用這個別名作克隆和更新 Host 172.16.11.11 HostName 172.16.11.11 User work IdentityFile ~/.ssh/id_rsa_work
這樣每次push的時候系統就會根據不一樣的倉庫地址使用不一樣的帳號提交了gitlab
直接更改 repo/.git/config
裏面的url便可,把裏面對應tag下的url增長一個就能夠了。例:fetch
[remote "GitHub"] url = git@github.com:elliottcable/Paws.o.git fetch = +refs/heads/*:refs/remotes/GitHub/* [branch "Master"] remote = GitHub merge = refs/heads/Master [remote "Codaset"] url = git@codaset.com:elliottcable/paws-o.git fetch = +refs/heads/*:refs/remotes/Codaset/* [remote "Paws"] url = git@github.com:Paws/Paws.o.git fetch = +refs/heads/*:refs/remotes/Paws/* [remote "Origin"] url = git@github.com:Paws/Paws.o.git url = git@codaset.com:elliottcable/paws-o.git
上面這個當即就是有4個遠端倉庫,不一樣的tag表示不一樣的遠端倉庫,最後的Origin標籤寫法表示默認push到github和codaset這兩個遠端倉庫去。固然,你能夠本身隨意定製tag和urlurl
http://stackoverflow.com/questions/849308/pull-push-from-multiple-remote-locations/3195446#3195446code
http://happy123.me/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/