logo
4
5
Login
📝 docs: 更新README中的仓库URL为cnb.cool域名

gsync

gsync 是一个用于在 Git 平台(如 GitHub、Gitee、CNB、Gitea 等)之间同步 Releases(包含 Release 元数据及附件)的命令行工具,支持分支/标签推送、Release 上传下载、断点续传等功能。

🔥 主要功能

  • 跨平台仓库迁移:在不同的Git代码托管平台之间无缝迁移仓库
  • 选择性迁移:支持只迁移特定的分支和标签
  • 发布管理:上传、下载、创建和同步发布版本及附件
  • 批量操作:支持在组织或用户级别进行批量仓库同步
  • 多平台支持:兼容GitHub、Gitee、Gitea和cnb.cool

🚀 安装指南

从源码安装

  • 确保你已安装Go 1.23+
  • 克隆仓库并编译
git clone https://github.com/chihqiang/mpgrm.git cd mpgrm && make build

编译后的可执行文件将位于项目根目录

一键安装(推荐)

curl -sSL https://cnb.cool/zhiqiangwang/gsync/-/git/raw/main/install.sh | bash

环境配置

复制环境变量示例文件

cp .env.example .env

编辑.env文件并根据你的平台添加相应的认证信息

# CNB平台用户名(CNB没有个人仓库,只有组织。 # 此值用作"个人仓库"标识符) CNB_USERNAME="cnb" # CNB平台访问令牌 CNB_TOKEN="token_cnb_abcdef123456" # Gitea平台用户名 GITEA_USERNAME="gitea" # Gitea平台访问令牌 GITEA_TOKEN="a1b2c3d4e5f6g7h8i9j0klmnopqrstuvwx" # Gitee平台用户名 GITEE_USERNAME="gitee" # Gitee平台访问令牌 GITEE_TOKEN="z9y8x7w6v5u4t3s2r1q0ponmlkjihgfedcba" # GitHub用户名 GITHUB_USERNAME="github" # GitHub个人访问令牌 GITHUB_TOKEN="ghp_FAKE1234567890abcdefABCDEFabcdef"

💻 使用示例

凭证管理 (credential)

轻松管理仓库凭证,随时推送

# 基本用法 # 通过命令行直接指定仓库URL。 # 默认行为(是否从环境变量读取)由--use-env控制。 gsync credential show --repo https://cnb.cool/username/source-repo.git # 指定仓库URL并明确禁用从环境变量读取。 # --use-env=false表示命令将只使用通过--repo提供的URL。 gsync credential show --use-env=false --repo https://cnb.cool/username/source-repo.git

推送仓库 (push)

将源仓库中的指定分支和标签推送到目标仓库

# 基本用法 gsync push --repo https://cnb.cool/username/source-repo.git --target-repo https://gitee.com/username/target-repo.git # 选择性推送特定分支和标签 gsync push --repo https://cnb.cool/username/source-repo.git --target-repo https://gitee.com/username/target-repo.git --branches main,develop --tags v1.0.0,v1.1.0 # 指定工作区目录 gsync push --repo https://cnb.cool/username/source-repo.git --target-repo https://gitee.com/username/target-repo.git --workspace /path/to/workspace

管理发布版本 (releases)

上传发布文件

gsync releases upload --repo https://cnb.cool/username/repo.git --tags v1.0.0 --files path/to/file1.zip,path/to/file2.tar.gz

下载发布文件

gsync releases download --repo https://cnb.cool/username/repo.git --tags v1.0.0,v1.1.0

为所有标签创建发布版本

gsync releases create --repo https://cnb.cool/username/repo.git

同步发布版本

gsync releases sync --repo https://cnb.cool/username/source-repo.git --target-repo https://gitee.com/username/target-repo.git --tags v1.0.0,v1.1.0

管理仓库 (repo)

列出仓库

# 列出组织的所有仓库 gsync repo list --repo https://cnb.cool/organization/ # 列出用户的所有仓库 gsync repo list --repo https://cnb.cool

克隆仓库

# 列出并克隆组织的所有仓库 gsync repo clone --repo https://cnb.cool/<organization>/ # 列出并克隆用户的所有仓库 gsync repo clone --repo https://cnb.cool/<username>

同步仓库

# 同步组织的所有仓库 gsync repo sync --repo https://cnb.cool/organization/ --target-repo https://gitee.com/organization/ # 同步用户的所有仓库 gsync repo sync --repo https://cnb.cool --target-repo https://gitee.com

为什么要使用mpgrm做为基础呢

使用 mpgrm 作为基础,是为了复用已有稳定逻辑,保证统一性和可维护性;而对 gsync 出现同名脚本冲突的问题,需要通过整体架构调整(命名隔离、统一入口、继承基础)来解决。

repo & target-repo 使用指南

CloneURL根据尾部字符确定它指向的是组织还是仓库

组织URL(以/结尾)

  • 表示组织路径。
  • 需要附加仓库名称以生成完整的仓库URL。
  • 目前,不以/结尾的URL(例如https://cnb.cool/org)不被支持。
  • 示例:
https://cnb.cool/org/ -> org https://cnb.cool/org1/ -> org1 https://cnb.cool/org1/child1/ -> org1/child1 https://cnb.cool/org1/child1/child2/ -> org1/child1/child2

个人仓库或根URL

  • 指向域名根目录或用户主页的URL。

  • 通常仅作参考;不暗示任何仓库。

  • 示例:

https://cnb.cool/ https://cnb.cool

仓库URL(不以/结尾或以.git结尾)

https://cnb.cool/org/repo.git https://cnb.cool/org1/child1

⚠️ 注意: **尾部的/**是区分组织URL和仓库URL的关键。 组织URL需要附加仓库名称,而仓库URL已经是完整的。