gsync

command module
v0.0.0-...-5b13e22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

gsync

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

✨ 功能特性

  • 同步 Git 仓库的分支和标签
  • 同步 Releases(标题、描述、是否为草稿/预发布等元信息)
  • 支持上传/下载 Release 附件
  • 支持 Github、Gitee、Gitea 等平台(可扩展更多)
  • 附件下载支持断点续传
  • CLI 命令统一,自动补全 & 错误提示
  • 可配置的工作目录、认证信息、强制推送等参数
  • 支持 slog 日志,日志更友好

🧩 命令用法

🗂Git命令

🔄同步分支/标签

--source-username--source-token 可以不填写,gsync 会优先从 .env 文件或系统环境变量中读取(如 GITHUB_USERNAMEGITHUB_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
📥 Clone账号所有仓库
gsync git clone \
  --source-repo https://github.com/foo \
  --source-username yourname \
  --source-token yourtoken 
✏️ 修改提交记录中的邮箱

参数 --new-name--new-email 的获取优先级如下:

  1. 命令行传入的值(即显式指定)
  2. 本地仓库配置(.git/config 中的 [user] 段)
  3. 全局 Git 配置(~/.gitconfig 中的 [user] 段)
gsync git rewriter \
	--old-email="[email protected]"  \
	--new-name="new-name" \
	--new-email="[email protected]"

🗃 repo命令

🌍 创建多平台同名仓库

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

📦 Release 命令

📤 上传 Release 附件
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
📥 下载 Release 附件
gsync releases download \
  --source-repo https://github.com/user/repo.git \
  --source-username yourname \
  --source-token yourtoken \
  --tag v1.2.3 
🆕根据tag创建Release(不包含附件)

可以使用 --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
🔄 同步 Releases附件
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

❓ 常见问题(FAQ)

Q: --source-username--source-token 可以不填吗?

A: 可以,gsync 会优先从 .env 文件或环境变量(如 GITHUB_USERNAMEGITHUB_TOKEN)读取。但 Gitee 的 --target-username--target-token 必须填写,否则推送会失败。

Q: 为什么推送到 Gitee 必须使用账号和密码?

A: 因为 Gitee 的 Personal Access Token 不能用于 Git 推送认证,推送时仍然要求账号+密码形式登录。推荐使用账号+密码确保推送正常。

Q: 修改提交历史后如何更新远程仓库?

A: 需要执行强制推送命令:git push origin --force --allgit push origin --force --tags,否则远程仓库不会自动更新。

🧱 平台支持

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cnb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL