GitHub Sync

––– views

Sync 2 repositories on push.

Generate Personal Access Token

The GitHub Account must have access to both repositories.

  1. Visit Token Settings

  2. Generate a new token

    ![

  3. Fill as below, this will be used to force push changes to the production repository

  4. Copy the Personal Access Token and save it.

Development Repository Setup

  1. Save this workflow as .github/workflows/git-sync.yml
.github/workflows/git-sync.yml
name: Git Sync
on:
  push:
    branches:
      - main
  workflow_dispatch:
jobs:
  git-sync:
    if: ${{ github.repository == 'username/dev-repo-name' }}
    runs-on: ubuntu-latest
    steps:
      - name: 🛑 Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.9.1
      - name: 🔗 Synchronize Repository
        uses: wei/git-sync@v3
        with:
          source_repo: 'https://username:${{ secrets.PAT }}@github.com/username/dev-repo-name.git'
          source_branch: 'main'
          destination_repo: 'https://username:${{ secrets.PAT }}@github.com/username/production-repo-name.git'
          destination_branch: 'main'
Don't forget to change the username and repo name
  1. Add PAT to the GitHub secrets

Production Repository Setup

No setup is needed.