Automatically synchronize directories to other branches within the same repository.
Whenever the action is called with the given map
configuration, it will force push the specified directories to the target branches. It will also check for changes against the previous commit to avoid unnecessary force pushes.
Usecases:
- Syncing each directory in
templates/
to individual branches to allow quick cloning. - Syncing the
docs
directory to thegh-pages
branch to update the website.
See the example below for more information.
In most cases, you only need the workflow below. Feel free to copy it and edit the map
field to your needs.
name: Sync
on:
# Allow manually triggering the workflow (optional, but helpful)
workflow_dispatch:
inputs:
skip-unchanged-check:
type: boolean
default: false
dry-run:
type: boolean
default: false
# Automatically trigger the workflow on push to the master branch
push:
branches:
- master
# Enable write permission to allow force pushing changes to the repo
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
# Checkout the repository to access the files
- uses: actions/checkout@v4
with:
fetch-depth: 2 # fetch 2 to compare with previous commit for changes
# Run the action to synchronize the branches
- uses: bluwy/auto-branch-sync-action@v1
with:
# example line-separated config:
# 1. Maps the root of the repository to the `sync/root` branch
# 2. Maps the `test-fixtures` directory to the `sync/fixtures-root` branch
# 3. Maps the `test-fixtures/*` directory to the `sync/fixtures-sub/*` branch
# (e.g. `test-fixtures/bar` -> `sync/fixtures-sub/bar`)
# 4. Maps the `test-fixtures/**/nested` directory to the `sync/fixtures-nested/**` branch
# (e.g. `test-fixtures/foo/nested` -> `sync/fixtures-nested/foo`)
map: |
/ -> sync/root
/test-fixtures -> sync/fixtures-root
/test-fixtures/* -> sync/fixtures-sub/*
/test-fixtures/**/nested -> sync/fixtures-nested/**
# Optional: Skip the check for unchanged files (only recommended for debugging)
skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
# Optional: Dry run to see the changes without apply any git actions (only recommended for debugging)
dry-run: ${{ inputs.dry-run == true }}
The config above is used by this repo's test.yml
to test the action. Check out the logs and branches to see it in action.
- Ignore certain directories from glob
- Specify a nested target directory in the target branch
- Specify a custom commit message, username, and email
Feel free to submit a PR if you need them!
MIT