千家信息网

项目同步两个git仓库后如何同时传到gitee和github

发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,本篇内容主要讲解"项目同步两个git仓库后如何同时传到gitee和github",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"项目同步两个git仓库后如何同
千家信息网最后更新 2025年12月03日项目同步两个git仓库后如何同时传到gitee和github

本篇内容主要讲解"项目同步两个git仓库后如何同时传到gitee和github",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"项目同步两个git仓库后如何同时传到gitee和github"吧!

有时候我们为了保证仓库代码安全,可能将git代码传送到两个不同的git代码仓库。接下来演示下如何进行操作:

  1. 首先创立两个仓库

    #假定创建好的两个仓库地址分别为:https://gitee.com/cigoos/mycode.githttps://github.com/cigoos/mycode.git


  2. 先从其中一个仓库检出代码

    git clone https://gitee.com/cigoos/mycode.git


  3. 删除仓库origin

    git remote rm origin


  4. 关联两个远程仓库

    # 关联giteegit remote add gitee https://gitee.com/cigoos/mycode.gitgit push gitee master# 关联githubgit remote add github https://github.com/cigoos/mycode.gitgit 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 dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (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


  5. 删除分支

    git push origin --delete devgit branch -D dev


  6. 检出本地分支

    #基于gitee/master创建本地分支giteegit checkout -b gitee/master gitee


  7. 合并分支

    git merge --squash dev --allow-unrelated-histories


到此,相信大家对"项目同步两个git仓库后如何同时传到gitee和github"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

0