自动保持辅助回购与主回购协议同步? [英] Automatically keep a secondary repo in sync with a primary repo?

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

问题描述

我们有一个双层设置。

我们有一个主存储库(下面称为'primary')。

以及创建如下所示的辅助存储库(称为'secondary'):

  $ git clone --bare - 共享$ REPO_A / primary secondary.git 

在辅助资源库中工作的人员查看起源的分支从主存储库中作为只读存储,但是将它们自己的分支基于这些分支。



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



即,我们需要提交给主要的提交和新分支,以便在辅助存储库中工作的人员可见(下次他们进行提取时)。



我们不希望这是对称的,即针对二级存储库的活动对于那些处理主存储库的人不会看到。



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



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

如果我要写一个脚本来做到这一点,它会这样做:




  • 创建辅助副本的全新副本。

      $ cd secondary 


  • 获取所有分支。

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


  • 获取主回购。

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


  • 我没有相应的辅助分支:

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


  • 我已经拥有相应的二级分行:

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




因为我是git的新手,如果我没有考虑到某些基本问题,我不会感到惊讶吗?

就像我说过的,我希望有一个更简单的方法来做到这一点,即有人会哦,不要做所有的事情,只是做...。

解决方案

哦,不要这样做,只要做:

  git --bare获取

;)



(见旧线程例如

如果您添加了相关的远程起源到您的裸回购,您可以依次取回每个起源。


We have a two tier setup.

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.

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
    

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

;)

(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天全站免登陆