gsync 是一个用于在 Git 平台(如 GitHub、Gitee 等)之间同步 Releases(包含 Release 元数据及附件)的命令行工具,支持分支/标签推送、Release 上传下载、断点续传等功能。
slog 日志,日志更友好curl -sSL https://cnb.cool/zhiqiangwang/gsync/-/git/raw/main/install.sh | bash
--source-username和--source-token可以不填写,gsync 会优先从.env文件或系统环境变量中读取(如GITHUB_USERNAME、GITHUB_TOKEN)。Gitee 例外:必须填写
--target-username和--target-token,原因是:Gitee 的 Personal Access Token 无法用于 Git 推送,推送时仍然要求使用 账号+密码的形式登录。推荐直接填写 Gitee 的 用户名 + Git 令牌(或密码) 来确保推送正常完成。源和目标仓库需提前创建,gsync 不会自动创建仓库。
默认同步全部分支和标签,不包含 Releases。
gsync git push \ --source-repo https://github.com/user/repo.git \ --source-username yourname \ --source-token yourtoken \ --target-repo https://gitee.com/user/repo.git \ --target-username yourname \ --target-token yourtoken
gsync git clone \
--source-repo https://github.com/foo \
--source-username yourname \
--source-token yourtoken
参数
--new-name和--new-email的获取优先级如下:
- 命令行传入的值(即显式指定)
- 本地仓库配置(
.git/config中的[user]段)- 全局 Git 配置(
~/.gitconfig中的[user]段)
gsync git rewriter \
--old-email="old@email.com" \
--new-name="new-name" \
--new-email="new@email.com"
按
source-repo读取仓库信息,批量在 GitHub、Gitee、Gitea 下创建同名仓库。
https://github.com→ 个人账户
https://github.com/yourorg→ 组织仓库支持并发批量创建,日志实时输出。
gsync repo create \ --source-repo https://github.com/user/repo.git \ --source-username yourname \ --source-token yourtoken \ --provider-origins https://github.com \ --provider-origins https://gitea.com \ --provider-origins https://gitee.com \ --provider-origins https://cnb.cool/orginName \
INFO 日志表示该仓库符合处理条件,正在进行相关操作。
WARN 日志表示该仓库被识别为需跳过的仓库,处理流程将忽略它。
gsync repo list \ --source-repo https://github.com/user/repo.git \ --source-username yourname \ --source-token yourtoken \ --ignore repo_name1 \ --ignore repo_name2 \
--source-repo:指定仓库地址,程序会自动提取其中的组织名或用户名;若提取结果与当前用户名相同,则删除个人仓库,否则删除组织仓库。本命令操作危险,建议先使用
gsync repo list命令查看仓库列表,确认无误后再执行删除操作。
gsync repo delete \ --source-repo https://github.com/user/repo.git \ --source-username yourname \ --source-token yourtoken \ --ignore repo_name1 \ --ignore repo_name2 \
--source-repo指定源仓库路径。若为组织地址(如
https://github.com/foo),则同步该组织下的所有仓库;若为授权用户地址(如
https://github.com/yourname),则同步该用户拥有的所有仓库(包括其所属组织的仓库)。
--target-repo指定目标仓库路径前缀,必须显式包含组织或用户名(即使是个人账号,也要写出来),用于拼接最终目标仓库地址。
--ignore指定忽略的仓库名称,可重复使用。被忽略的仓库将不会被同步。
gsync repo sync \
--source-repo https://github.com/foo \
--source-username yourname \
--source-token yourtoken \
--target-repo https://gitee.com/foo \
--target-username yourname \
--target-token yourtoken \
--ignore repo_name1 \
--ignore repo_name2
gsync releases upload \ --target-repo https://github.com/user/repo.git \ --target-username yourname \ --target-token yourtoken \ --tag v1.2.3 \ --file ./build.zip \ --file ./changelog.md
gsync releases download \ --source-repo https://github.com/user/repo.git \ --source-username yourname \ --source-token yourtoken \ --tag v1.2.3
可以使用
--tag或--tags指定一个或多个 Git tag。如果 同时未传入
--tag和--tags,则默认会从仓库中获取所有 tag,并尝试为每个 tag 创建 Release。若某个 tag 已存在对应 Release,将自动跳过,避免重复创建。
gsync releases create \ --source-repo https://github.com/user/repo.git \ --source-username yourname \ --source-token yourtoken \ --tags v0.0.1 \ --tags v0.0.2
gsync releases sync \
--source-repo https://github.com/user/repo.git \
--source-username yourname \
--source-token yourtoken \
--target-repo https://gitee.com/user/repo.git \
--target-username yourname \
--target-token yourtoken \
--tags v1.0.0 \
--tags v1.2.3
A: 可以,gsync 会优先从 .env 文件或环境变量(如 GITHUB_USERNAME、GITHUB_TOKEN)读取。但 Gitee 的 --target-username 和 --target-token 必须填写,否则推送会失败。
A: 因为 Gitee 的 Personal Access Token 不能用于 Git 推送认证,推送时仍然要求账号+密码形式登录。推荐使用账号+密码确保推送正常。
A: 需要执行强制推送命令:git push origin --force --all 和 git push origin --force --tags,否则远程仓库不会自动更新。