Skip to content
Latchkey

πŸ”„ Sync all branches with main workflow (6Kmfi6HP/EDtunnel)

The πŸ”„ Sync all branches with main workflow from 6Kmfi6HP/EDtunnel, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: 6Kmfi6HP/EDtunnel.github/workflows/sync.ymlLicense MITView source

What it does

This is the πŸ”„ Sync all branches with main workflow from the 6Kmfi6HP/EDtunnel repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: "πŸ”„ Sync all branches with main"

on:
  workflow_dispatch:

jobs:
  sync_branches:
    runs-on: ubuntu-latest
    name: "πŸ”„ Sync branches with main"
    env:
      EMAIL: ${{ secrets.GH_EMAIL }}
      NAME: ${{ secrets.GH_USERNAME }}
      TOKEN: ${{ secrets.TOKEN }}
      REMOTE_NAME: origin
      BRANCH_BASE_NAME: proxyip
      BRANCH_COUNT: 200

    steps:
      - name: πŸ›  Set up Git config
        run: |
          git config --global user.email "${{ env.EMAIL }}"
          git config --global user.name "${{ env.NAME }}"

      - name: πŸ“₯ Clone repository
        run: |
          git clone https:///${{ env.TOKEN }}@github.com/${{github.repository}}.git
          cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')

      - name: πŸ”„ Sync and push branches
        run: |
          cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')
          git checkout main
          git pull ${REMOTE_NAME} main
          for ((i=1; i<=${{ env.BRANCH_COUNT }}; i++)); do
            branch_name="${{ env.BRANCH_BASE_NAME }}${i}"
            git checkout $branch_name
            git merge main --no-edit
            git push ${REMOTE_NAME} $branch_name
            git checkout main
          done

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: "πŸ”„ Sync all branches with main"
 
on:
  workflow_dispatch:
 
jobs:
  sync_branches:
    timeout-minutes: 30
    runs-on: latchkey-small
    name: "πŸ”„ Sync branches with main"
    env:
      EMAIL: ${{ secrets.GH_EMAIL }}
      NAME: ${{ secrets.GH_USERNAME }}
      TOKEN: ${{ secrets.TOKEN }}
      REMOTE_NAME: origin
      BRANCH_BASE_NAME: proxyip
      BRANCH_COUNT: 200
 
    steps:
      - name: πŸ›  Set up Git config
        run: |
          git config --global user.email "${{ env.EMAIL }}"
          git config --global user.name "${{ env.NAME }}"
 
      - name: πŸ“₯ Clone repository
        run: |
          git clone https:///${{ env.TOKEN }}@github.com/${{github.repository}}.git
          cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')
 
      - name: πŸ”„ Sync and push branches
        run: |
          cd $(echo ${{github.repository}} | awk -F'/' '{print $2}')
          git checkout main
          git pull ${REMOTE_NAME} main
          for ((i=1; i<=${{ env.BRANCH_COUNT }}; i++)); do
            branch_name="${{ env.BRANCH_BASE_NAME }}${i}"
            git checkout $branch_name
            git merge main --no-edit
            git push ${REMOTE_NAME} $branch_name
            git checkout main
          done
 

What changed

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.