name: Sync main and master branches on: push: branches: - main - master jobs: sync: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - name: Setup Git run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Sync branches run: | # Get the branch that was pushed to PUSHED_BRANCH="${GITHUB_REF#refs/heads/}" if [ "$PUSHED_BRANCH" = "main" ]; then TARGET_BRANCH="master" else TARGET_BRANCH="main" fi echo "Syncing $PUSHED_BRANCH → $TARGET_BRANCH" git fetch origin $TARGET_BRANCH || git checkout -b $TARGET_BRANCH git checkout $TARGET_BRANCH git merge origin/$PUSHED_BRANCH --no-edit -m "Sync from $PUSHED_BRANCH" git push origin $TARGET_BRANCH