gsync 是一个用于在 Git 平台(如 GitHub、Gitee、CNB、Gitea 等)之间同步 Releases(包含 Release 元数据及附件)的命令行工具,支持分支/标签推送、Release 上传下载、断点续传等功能。
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"
轻松管理仓库凭证,随时推送
# 基本用法
# 通过命令行直接指定仓库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
将源仓库中的指定分支和标签推送到目标仓库
# 基本用法
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
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
# 列出组织的所有仓库
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 作为基础,是为了复用已有稳定逻辑,保证统一性和可维护性;而对 gsync 出现同名脚本冲突的问题,需要通过整体架构调整(命名隔离、统一入口、继承基础)来解决。
CloneURL根据尾部字符确定它指向的是组织还是仓库。
/结尾的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。
通常仅作参考;不暗示任何仓库。
示例:
https://cnb.cool/
https://cnb.cool
https://cnb.cool/org/repo.git
https://cnb.cool/org1/child1
⚠️ 注意: **尾部的
/**是区分组织URL和仓库URL的关键。 组织URL需要附加仓库名称,而仓库URL已经是完整的。