项目同步两个git仓库,如同时传到gitee和github
有时候我们为了保证仓库代码安全,可能将git代码传送到两个不同的git代码仓库。接下来演示下如何进行操作:
首先创立两个仓库
#假定创建好的两个仓库地址分别为:
https://gitee.com/cigoos/mycode.git
https://github.com/cigoos/mycode.git
先从其中一个仓库检出代码
git clone https://gitee.com/cigoos/mycode.git
删除仓库origin
git remote rm origin
关联两个远程仓库
# 关联gitee
git remote add gitee https://gitee.com/cigoos/mycode.git
git push gitee master
# 关联github
git remote add github https://github.com/cigoos/mycode.git
git push github master
# 注意此时如果遇到下述问题
To https://github.com/CigoOS/cigoadmin_tp5.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/cigoos/mycode.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
# 此时要先执行
git pull github master --allow-unrelated-histories
项目同步两个git仓库,如同时传到gitee和github
https://blog.jeecloud.cn/2020/04/13/20200414021500/