Keep two repositories in sync
Gunar Gessner
Aug 12, 2021
This is a GitHub Action template for force-pushing one repo into another once every day.
- Create a new repo called
repo-sync
- Create a Personal Access Token for GitHub
- Add the token as a secret called
PERSONAL_ACCESS_TOKEN
- Put the code below into
.github/workflows/sync.yml
and replace the<variables>
- Profit (i.e. you're done!)
name: "Daily sync"
on:
push:
branches:
- main
schedule:
- cron: "0 0 * * *"
jobs:
backup:
runs-on: ubuntu-latest
name: Sync repos
steps:
- name: sync
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
USERNAME: <your-username>
REPO_FROM: <org/repo>
REPO_TO: <org/repo>
run: |
set -xe
git clone "https://${USERNAME}:${PERSONAL_ACCESS_TOKEN}@github.com/${REPO_FROM}.git" .
git remote add fork "https://{$USERNAME}:${PERSONAL_ACCESS_TOKEN}@github.com/${REPO_TO}.git"
git fetch fork
git push --force fork origin/main:main