Skip to content

Mirroring an External Repository

Robyn Verrinder edited this page Jul 3, 2026 · 1 revision

Mirroring an External Repository

Research or teaching work hosted outside the organisation, for example on a personal account or a collaborator's account, should be mirrored here where the department retains an interest in it. A mirror is a copy kept up to date with the upstream repository. It is not a fork: a fork is for proposing changes or starting a new line of development, whereas a mirror simply tracks the original.

Manual mirror

For an occasional copy:

git clone --mirror https://github.com/UPSTREAM_OWNER/REPO.git
cd REPO.git
git remote set-url --push origin https://github.com/uct-eee-department/REPO.git
git push --mirror

Repeat the final push whenever you want to update the mirror.

Automatic mirror with GitHub Actions

To keep a mirror in sync automatically, add a scheduled workflow to the upstream repository. A minimal example, saved as .github/workflows/mirror.yml:

name: Mirror to organisation
on:
  push:
  schedule:
    - cron: '0 3 * * 0'
  workflow_dispatch:
jobs:
  mirror:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Push to mirror
        run: |
          git push --mirror https://x-access-token:${{ secrets.MIRROR_TOKEN }}@github.com/uct-eee-department/REPO.git

This needs a token with write access to the organisation repository, stored as a repository secret named MIRROR_TOKEN. Adjust the schedule to suit. Note that git push --mirror makes the target match the source exactly, including deleting refs that no longer exist upstream, which is what keeps a true mirror in step.

Clone this wiki locally