Github Action for mirroring repositories

In some cases, it is useful to mirror a repository on GitHub. Unfortunately, Github does not provide an automatic mirroring feature so far. The only way to make mirroring is to do it yourself manually or automate it. Thanks to Github Actions, we will be able to mirror a repository on GitHub automatically.

To do so, we will need to create a new repository on GitHub and then we will need to create a new Github action using repo-sync/github-sync action. You can copy the code below and paste it into your mirrored repository.

.github/workflows/repo-sync.yml
on:
  schedule:
    - cron: '0 * * * *'
  workflow_dispatch:

jobs:
  repo-sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          persist-credentials: false

      - name: repo-sync
        uses: repo-sync/github-sync@v2
        with:
          source_repo: 'org/repo'
          source_branch: 'main'
          destination_branch: 'main'
          github_token: ${{ secrets.PAT }}

You will need to update the source_repo, source_branch, and destination_branch values to match your repository.

Do not forget to fill in the PAT Github secret. For creating a new Personal Access Token, please follow the Github docs.

For more information about this Github Action, please visit here.

Consulting

If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.

Share this post
Follow the RSS feed