Github Action for mirroring repositories

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/[email protected]
        with:
          persist-credentials: false

      - name: repo-sync
        uses: repo-sync/github-[email protected]
        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.

Share this post
Follow the RSS feed

Subscribe to the newsletter

Get emails from me about web development and a lot of topics related to tech.