首页 > 解决方案 > 在 git 中链接两个存储库

问题描述

我们有一组 git 存储库,用于开发我们的产品。这些存储库在 bitbucket 或 gitlab 中进行管理,并托管在本地或云端。对这些 repo 所做的更改需要定期(比如每月一次)传播到 github 中托管的一组公共 repo。这个要求是为了支持我们的 beta 计划,我们在公开之前测试更改(使其成为 GA)。是否有任何标准模式可用于此目的?

标签: gitgithub

解决方案


Clone the Bitbucket repository to your local machine:

$ git clone --mirror ssh://git@bitbucket.org:your_name/your_repo.git

Then you basically have to run these two commands every month:

$ git remote update --prune
$ git push --mirror git@github.com:your_name/your_repo.git

Linux and Cron

If you have a Linux machine/Linux server/WSL edit your crontabs:

$ crontab -e

Add this crontab:

@monthly git -C <local_repo_path> remote update --prune && git -C <local_repo_path> push --mirror git@github.com:your_name/your_repo.git

macOS and Cron

Automating tasks using Cron is very similar to the way it's done in Linux, follow this guide to get started.

Windows and Scheduled Task

I am not very familiar with Schtasks, but I this is how you would automate the task:

> schtasks /create /tn git-mirror /tr git -C <local_repo_path> remote update --prune && git -C <local_repo_path> push --mirror git@github.com:your_name/your_repo.git /sc weekly /d MON /ru "System"

推荐阅读