How to keep two branches in sync on Github

GitHub Actions allows you to automate, customize and execute your software development workflows inside your repository.

Photo by James Harrison on Unsplash

Let’s say we have two branches master and develop in our repositories following GitFlow methodology. We often encounter a situation when a hotfix is merged directly to master then those changes has to be reverse merged to develop else they will not get reflected in the `develop` branches thereby creating an inconsistency.

We can set up a workflow using Github Actions to keep two branches in sync. To do so, we only need repositories enabled with GitHub Action workflows.

At the time of write, GitHub Actions are free for public repositories and have a limit of 2000 mins for a free account.

Let’s get into action,

  • Now create a workflows folder under .github. This holds all the action workflows configured for the repository.

Here we are creating a Sync Back to Develop workflow that runs the sync-branches job when changes are pushed to master remote branch. We won't be getting into details about the configuration file as this beyond our article's scope. To learn more, you can get started with the official docs.

We are making use of tretuna/sync-branches action. This action provides options which allows to configure the branch names and details of the PR raised.

Crazy Stuff. Now bots can raise PR and merge one based on conditions without manual intervention.

We have now successfully automated the workflow. We have merely touched the surface, we can do more with GitHub Actions. The sky is the limit for ideas.

Happy Solving!.

Reference

Originally published at https://bharathvaj.me.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store