说明:此前参考了某个资料,但是实在记不得来源了!
目的:
1 . 为了同时在两个git仓库中备份代码,以避免某个仓库崩溃的情况!
2. 以git push origin master 同时备份两个仓库(以oschina 与 csdn为例)
步骤:
1. 分别在两个仓库建立相应的项目
2. git remote add origin AAA
3. git remote add origin BBB 此时会提示,origin 已经存在,我们通过编辑 项目中的文件夹 ~/.git/config
将
[remote "origin"]
url = AAA
fetch = +refs/heads/*:refs/remotes/origin/
修改为
[remote "origin"]
url = AAA
url = BBB
fetch = +refs/heads/*:refs/remotes/origin/
4. git push origin master 成功
5. 此时需要输入密码,可通过相应设置来实现无密码访问,
成功后配置文件 .git-credentials中内容为:
https://user:passwd@code.youkuaiyun.com
https://user:passwd@git.oschina.net