GitHub Workflow to Sync Branches
Created on .
Read in 1 minute.
I have a GitHub repository using
main as the default branch, but I am trying to integrate a third party tool (loading JSFiddle contents from GitHub) that has
master hardcoded as the default branch.
There is an issue in the tool, but stale bot has killed it.
- Every push to main will also be applied to master.
- Both branches will share the same refs and tags.
- No workflows will execute on pushes to the
- No manual interaction is required (no pull requests).
- A maximum delay of only a few minutes.
Below is a simple GitHub workflow that pushes
master. The key option to be aware of is the
fetch-depth for actions/checkout, which fetches all branches and tags for the repository. The default is to only get the current branch.
Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags. Refer here to learn which commit $GITHUB_SHA points to for different events.
name: Push to Master
- uses: actions/checkout@v2
- name: Update master branch from main
git config --global user.name 'Justin Poehnelt'
git config --global user.email 'firstname.lastname@example.org'
git checkout master
git reset --hard origin/main
git push origin master
Depending on how you use GitHub workflows, you may also want to ignore the
master branch. The following workflow will trigger on every branch except
master using branches-ignore.
- Caching Playwright Binaries in GitHub Actions
- Environment Variables in GitHub Docker build-push-action
- Unwatch All Repositories in a GitHub Organization
- Automatically Approving and Merging Dependabot Pull Requests
- Using Google Container Registry, Docker Buildx, and GitHub Actions
- Drop Bag Plan for Cocodona 250
- What is DevRel?
- Rebasing All Dependabot Pull Requests
- Microservice Usage Logging with Openresty and Google BigQuery
- Automatically Archiving Dependabot and Semantic Release Emails