其他分享
首页 > 其他分享> > Git同时推送代码到Github与Gitee

Git同时推送代码到Github与Gitee

作者:互联网

文章转载:git技巧-项目同时推送至github和gitee

 

一次push推送代码到多个远程仓库(以第一个仓库为主,第二个仓库作为备份)

1.初始化本地仓库

git init

2.设置第一个目标远程仓库 Github

git remote add origin git@github.com:远程仓库地址

3.设置第二个目标远程仓库 Gitee

git remote set-url --add origin git@gitee.com:远程仓库地址

4.拉取第一个仓库的默认分支的代码到本地

git pull origin main

5.新建测试文件,推送到远程仓库,测试推送是否成功

touch info.txt

git add info.txt

git commit -m "update"

git push origin main

 

出现的问题:

推送时第一个仓库成功,第二个失败。错误代码:

error: failed to push some refs to 'gitee.com:远程仓库地址'

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 push origin main --force

标签:Git,origin,git,hint,仓库,Gitee,Github,push,推送
来源: https://www.cnblogs.com/shiningwonders/p/16383276.html