Skip to content

用 Gitee 镜像同步 GitHub 仓库,国内秒速 clone

对于需要反复 clone / pull 的大仓库,任何代理方案都不如"把仓库搬到国内"来得彻底。Gitee(码云)提供从 GitHub 一键导入与定时同步,导入后 clone 走国内带宽,速度可以跑满。

适合场景:公司内多人都要拉同一个开源大仓库、CI 环境频繁 clone、跟踪某个上游项目。

一键导入 GitHub 仓库

  1. 登录 gitee.com,点右上角 +从 GitHub / GitLab 导入仓库;
  2. 粘贴 GitHub 仓库地址,如 https://github.com/torvalds/linux;
  3. 选择公开/私有,点击导入,等待完成(大仓库需要几分钟)。

导入完成后用 Gitee 地址 clone:

bash
git clone https://gitee.com/你的用户名/仓库名.git

保持与上游同步

Gitee 仓库页面右上角有 "同步"按钮,点一下即可拉取 GitHub 上游的最新提交。

需要自动化的话,可以用 Gitee 的 WebHook + 定时任务,或在 CI 里定期触发一个同步脚本:

bash
# 同步脚本思路:本地中转
git clone --mirror https://github.com/user/repo.git
cd repo.git
git remote add gitee https://gitee.com/you/repo.git
git push --mirror gitee

双远程工作流:国内拉,GitHub 推

开发者常见的需求是:pull 走 Gitee(快),push 回 GitHub(保持上游)

bash
# clone 自 Gitee
git clone https://gitee.com/you/repo.git
cd repo

# 添加 GitHub 为第二远程
git remote add github https://github.com/user/repo.git

# 日常:从 gitee 拉,向 github 推
git pull origin main
git push github main

也可以把 push 默认指向 GitHub:

bash
git remote set-url --push origin https://github.com/user/repo.git
# 此后 git pull 走 gitee,git push 自动走 github

注意

  • Gitee 免费版单仓库有容量限制(以官方说明为准),超大仓库(几十 GB)可能导入失败;
  • 私有仓库导入需要授权 GitHub 账号,注意权限范围;
  • 镜像仓库的 Issue / PR 不会同步,只同步 Git 数据。

相关阅读

🎯 镜像失效、加速站不稳定?
一个稳定的机场可以同时解决 ChatGPT、Netflix、GitHub、Hugging Face 的访问问题。 我们整理了 17 家机场的价格、节点与适用场景对比,并按稳定 / 便宜 / 专线分了专题。

本站为技术学习交流站点,与 GitHub, Inc. 无任何隶属或官方关系。所有内容仅供技术研究与学习,请遵守所在国家/地区的法律法规。