自动使辅助存储库与主存储库保持同步? [英] Automatically keep a secondary repo in sync with a primary repo?

查看:31
本文介绍了自动使辅助存储库与主存储库保持同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两层设置.

我们有一个主存储库(以下称为主").

We have a primary repository (called 'primary' below).

还有一个像这样创建的二级存储库(下面称为二级"):

And a secondary repository (called 'secondary' below) that was created like so:

$ git clone --bare --shared $REPO_A/primary secondary.git

在辅助存储库上工作的人将源自主存储库的分支视为只读的,但他们自己的分支基于这些分支.

People working on the secondary repository view the branches which originated from the primary repository as read only but base their own branches off these branches.

我们希望每天将辅助存储库与主存储库同步一次.

We want to sync up the secondary repository with the primary repository once a day.

即我们希望推送到主存储库的提交和新分支对在辅助存储库工作的人可见(下次他们进行拉取时).

I.e. we want commits and new branches that were pushed to the primary to become visible to people working off the secondary repository (next time they do a pull).

我们不希望这是对称的,即针对辅助存储库的活动对于在主存储库工作的人来说是不可见的.

We do not want this to be symmetric, i.e. activity against the secondary repository will not become visible to those working off the primary repository.

理想情况下,我想运行一个 cron 作业,该作业在具有裸辅助存储库的机器上运行,该存储库以某种方式从主存储库获取新数据并自动将其包含到辅助存储库中.

Ideally I'd like to run a cron job that runs on the machine with the bare secondary repository that somehow fetches new data from the primary and automatically includes it into the secondary.

我希望有一种简单的方法可以做到这一点(我希望这里有人会告诉我有).

I was hoping there might be a simple way to do this (and I'm hoping someone here will tell me there is).

如果我要编写一个脚本来执行它,它会这样做:

If I were to write a script to do it, it would do:

  • 创建辅助节点的新克隆.

  • Create a fresh clone of the secondary.

$ git clone $REPO_B/secondary
$ cd secondary

  • 获取它的所有分支.

  • Get all its branches.

    $ git branch -r | sed 's?.*origin/??'
    

  • 获取主仓库中的所有分支.

  • Get all branches in the primary repo.

    $ git ls-remote --heads $REPO_A/primary | sed 's?.*refs/heads/??'
    

  • 对于我还没有对应的二级分支的每个主分支:

  • For each primary branch for which I don't already have a corresponding secondary branch:

    $ git fetch $REPO_A/primary $BRANCHNAME:$BRANCHNAME
    $ git push origin $BRANCHNAME:refs/heads/$BRANCHNAME
    

  • 对于我已经拥有相应二级分支的每个主分支:

  • For each primary branch for which I already have a corresponding secondary branch:

    $ git checkout -b $BRANCHNAME --track origin/$BRANCHNAME
    $ git pull $REPO_A/primary $BRANCHNAME
    $ git push
    

  • 由于我是 git 新手,如果我没有考虑某些基本问题,我不会感到惊讶?

    As I'm new to git I wouldn't be surprised if I've failed to consider certain fundamental issues?

    就像我说的那样,我希望有一种更简单的方法来做到这一点,即有人说哦,不要做所有这些,只要做......".

    And like I said I'm hoping there's a simpler way of doing this, i.e. someone goes "oh, don't do all that, just do...".

    推荐答案

    哦,别那么做,就做吧:

    Oh, don't do all that, just do:

    git --bare fetch
    

    ;)

    (例如,请参阅此 旧线程)
    如果您已将 relevant remote origins 添加到您的裸仓库中,则可以依次获取每个那些起源.

    (See this old thread for instance)
    If you have added the relevant remote origins to your bare repo, you can fetch in turn each of those origins.

    这篇关于自动使辅助存储库与主存储库保持同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆