6 个版本

0.14.12 2024年2月8日
0.14.10 2023年1月9日
0.14.6 2022年7月8日
0.14.4 2021年7月20日
0.10.0 2018年11月23日

开发工具 类别中排名 508

每月下载量 32

MIT 许可证

40KB
877

Git Mirror

Git Mirror 会监视 GitLab 或 GitHub 群组,并将其与外部 Git 仓库保持同步。

用法

安装 git 和 git-lfs。

  1. 在您的 gitlab 实例或 gitlab.com 上创建一个群组。例如 mirror-test
  2. 添加您想要同步的仓库。例如 my-project
  3. 以 YAML 格式为项目添加描述,其中包含一个 origin 字段。例如 origin: https://git.example.org/my-project.git
  4. 设置环境变量 PRIVATE_TOKEN 为个人访问令牌或您的私有令牌,并执行 git-mirror
export PRIVATE_TOKEN="<personal-access-token>"
git-mirror -g mirror-test

这将同步 gitlab.com 上的群组 mirror-test。如果您想在不同 GitLab 实例上同步群组,请使用 -u 标志。

git-mirror -g mirror-test -u http://gitlab.example.org

多个并发作业

git-mirror 允许使用 -c <n> 标志并行执行多个镜像作业。

git-mirror -g mirror-test -c 8

这将并行执行最多 8 个同步作业

描述格式

为了使 git-mirror 能够镜像仓库,它需要知道从哪里同步。为此,git-mirror 预期镜像项目的描述字段是有效的 YAML,且至少包含一个 origin 字段。

origin: https://git.example.org/my-project.git

当前支持的字段列表

  • origin 要镜像的源仓库

  • skip 通过添加 skip: true 临时排除项目同步

  • destination 预留供将来使用

  • lfs 使用 lfs: false 禁用特定仓库的 git lfs 镜像(默认为 true),仅当使用 --lfs 启动 git-mirror 时才相关

  • refspec 仅推送refspec。添加refspec列表以使用它。任何有效的refspec都是可能的。例如:

    refspec: ["master", "2.0", "+refs/tags/*:refs/tags/*"]
    

    另请参阅 https://git-scm.cn/book/en/v2/Git-Internals-The-Refspec

    注意:如果设置了该字段,则它将覆盖通过命令行选项 --refspec 指定的默认(全局)refspec。可以通过重复选项来设置多个ref。

其他任何字段都将被忽略

镜像到GitHub

git-mirror 还支持镜像到GitHub。

可以通过指定GitHub作为提供者来实现这一点

export PRIVATE_TOKEN="<personal-access-token>"
git-mirror -g mirror-test -p GitHub

这已经在github.com上进行了测试,但它也可能与GitHub的本地安装一起工作。

Docker

还有一个可用的Docker镜像。可以使用以下方法使用它:

docker run -e PRIVATE_TOKEN="x" bachp/git-mirror git-mirror -g mirror -u http://gitlab.example.com

构建和安装

为了构建此项目,您至少需要rust v1.18.0。获取rust的最简单方法是通过:rustup.rs

可以使用cargo构建该项目

cargo build

它们使用Git镜像

许可证

本项目采用MIT许可证 - 请参阅LICENSE文件以获取详细信息

依赖项

~11–25MB
~432K SLoC