title: Automatically keep a secondary repo in sync with a primary repo?
body: <p>We have a two tier setup.</p>
  
  <p>We have a primary repository (called 'primary' below).</p>
  
  <p>And a secondary repository (called 'secondary' below) that was created like so:</p>
  
  <pre><code>$ git clone --bare --shared $REPO_A/primary secondary.git
  </code></pre>
  
  <p>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.</p>
  
  <p>We want to sync up the secondary repository with the primary repository once a day.</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>I was hoping there might be a simple way to do this (and I'm hoping someone here will tell me there is).</p>
  
  <p>If I were to write a script to do it, it would do:</p>
  
  <ul>
  <li><p>Create a fresh clone of the secondary.</p>
  
  <pre><code>$ git clone $REPO_B/secondary
  $ cd secondary
  </code></pre></li>
  <li><p>Get all its branches.</p>
  
  <pre><code>$ git branch -r | sed 's?.*origin/??'
  </code></pre></li>
  <li><p>Get all branches in the primary repo.</p>
  
  <pre><code>$ git ls-remote --heads $REPO_A/primary | sed 's?.*refs/heads/??'
  </code></pre></li>
  <li><p>For each primary branch for which I don't already have a corresponding secondary branch:</p>
  
  <pre><code>$ git fetch $REPO_A/primary $BRANCHNAME:$BRANCHNAME
  $ git push origin $BRANCHNAME:refs/heads/$BRANCHNAME
  </code></pre></li>
  <li><p>For each primary branch for which I already have a corresponding secondary branch:</p>
  
  <pre><code>$ git checkout -b $BRANCHNAME --track origin/$BRANCHNAME
  $ git pull $REPO_A/primary $BRANCHNAME
  $ git push
  </code></pre></li>
  </ul>
  
  <p>As I'm new to git I wouldn't be surprised if I've failed to consider certain fundamental issues?</p>
  
  <p>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...".</p>