Automatic cascading branch merging in GitHub

Somebody who likes to code
Search for a command to run...

Somebody who likes to code
No comments yet. Be the first to comment.
Google processes tens of thousands of code changes every day across a codebase of hundreds of millions of lines. The secret isn't magic tooling — it's a documented, principled approach to code review

Amazon Simple Notification Service (SNS) looks straightforward on the surface — publish a message, deliver it to subscribers — but the gap between a topic that "works in dev" and one that is productio

Amazon Simple Queue Service (SQS) is deceptively simple to get started with, but surprisingly easy to misconfigure in ways that cause silent message loss, runaway costs, duplicate processing storms, o

HTTP API is the right default choice for the majority of .NET serverless workloads. At 70% less cost than REST API, lower latency, and native JWT authorization, it covers most production requirements

AWS Lambda has become a cornerstone of modern serverless architectures, but writing a function that "just works" is very different from writing one that is performant, cost-effective, secure, and read

If we are using Gitflow in our projects, once the release is ready to be shipped, sooner or later, it will be merged with the develop branch. The task is simple and could be handled manually, but what if we have something a bit more complex, like two or more active release branches? A change in a previous release has to be cascaded to the next one until it reaches the develop branch. And to all this, add a merge conflict during the process. Gitflow automerge is a GitHub Actions to help us to automate those cases.
release branch to the next one until reaching the develop branch. The branches need to follow the Semantic Versioning guidelines.name: automerge
on:
push:
branches:
- 'release/**'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: AutoMerge
uses: raulnq/git-flow-automerge@v0.4.1
with:
github_token: ${{ secrets.AUTOMERGE_TOKEN }}
release_branch_type: 'release'
develop_branch: 'develop'
release_branch_type: Release branch prefix, default value: releasedevelop_branch: Develop branch name, default value: developgithub_token: We can use the ${{ secrets.GITHUB_TOKEN }}, but there is a limitation explained here about creating recursive workflow runs. Instead, we can create a Personal Access Token (PAT) in an account with write access to the repository and then add a secret in our repository with that value.To test the action, we created a repository with a secret on it (from the PAT):

git clone https://github.com/raulnq/github-actions-sandbox.git
cd github-actions-sandbox
Add a file .github\workflows\automerge.yml with the following content:
name: automerge
on:
push:
branches:
- 'release/**'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: AutoMerge
uses: raulnq/git-flow-automerge@v0.4.1
with:
github_token: ${{ secrets.AUTOMERGE_TOKEN }}
release_branch_type: 'release'
develop_branch: 'develop'
Commit and push the changes:
git add .
git commit -m 'adding workflow'
git push origin main
release to the develop branchCreate and push the develop branch:
git checkout -b develop
git push origin develop
Create and push the release/1.0.0 branch:
git checkout -b release/1.0.0 develop
git push origin release/1.0.0
Create, make a commit and push the feature/myFeatureA branch:
git checkout -b feature/myFeatureA
git commit -m 'featurea A: change 1' --allow-empty
git push origin feature/myFeatureA
Create a pull request from feature/myFeatureA to release/1.0.0:
Merge the pull request and go to the Actions tab:
Switch to develop and pull the last changes:
git checkout develop
git pull origin develop
Create a file and push the changes:
"Hi" >> Hi.txt
git add .
git commit -m 'new file'
git push origin develop
Switch to feature/myFeatureA and pull the last changes:
git checkout feature/myFeatureA
git pull origin feature/myFeatureA
Create a file and push the changes:
"Hello" >> Hi.txt
git add .
git commit -m 'new file'
git push origin feature/myFeatureA
Create a pull request from feature/myFeatureA to release/1.0.0, merge it, and go to the Actions tab, now a pull request was created:
Fix the merge conflict in the pull request before continuing.
develop branchSwitch to develop and pull the last changes:
git checkout develop
git pull origin develop
Create and push the multiple release branches:
git checkout -b release/1.0.1 develop
git push origin release/1.0.1
git checkout -b release/1.1.0 develop
git push origin release/1.1.0
git checkout -b release/2.0.0 develop
git push origin release/2.0.0
Create, make a commit and push the feature/myFeatureA branch:
git checkout feature/myFeatureA
git commit -m 'featurea A: change 2' --allow-empty
git push origin feature/myFeatureA
Create a pull request from feature/myFeatureA to release/1.0.0, merge it and go to the Actions tab:
Thanks, and happy coding.