您的位置:首页 > 其它

git 同时向两个仓库提交同一个分支

2014-11-21 08:37 381 查看
说明:此前参考了某个资料,但是实在记不得来源了!

目的:

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.csdn.net https://user:passwd@git.oschina.net
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: