Sync 2 repositories on push.
Generate Personal Access Token
The GitHub Account must have access to both repositories.
-
Visit Token Settings
-
Generate a new token
![
-
Fill as below, this will be used to force push changes to the production repository
-
Copy the Personal Access Token and save it.
Development Repository Setup
- 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
-
Add PAT to the GitHub secrets
Production Repository Setup
No setup is needed.