I have two branches in my github repository - master and dev branch. I have a requirement where I need to merge master branch into dev branch under below conditions:
- Once a PR is merged into master branch directly then I need to merge master branch back to dev branch automatically.
- Whenever someone adds a commit into master branch directly then I need to merge
masterbranch back todevbranch automatically.
Is this possible to do by any chance? I believe we can make this work with git Hooks but I am not sure how to do it. Can someone provide an example on how to achieve this?
I read it online and looks like I can use post-receive hook with below content in it but I am confuse on how to do this only if someone adds a commit to master branch or any PR gets merged to master branch? Also is this even the right way to do it?
git checkout master
git pull
git checkout dev
git pull
git merge master --no-ff --no-edit
git push
I appreciate that it may not always be possible, owing to merge conflicts, but if it is possible, we'd like it to happen automatically.
Update
After reading more about Github Actions - I created a file like this .github/workflows/merge-back-to-dev.yml in my root folder of git repository with below content. Does this look right? Do I need all these fields like runs-on?
name: 'Nightly Merge'
on:
push:
branches:
- master
jobs:
nightly-merge:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Nightly Merge
uses: robotology/gh-action-nightly-merge@v1.3.1
with:
stable_branch: 'master'
development_branch: 'dev'
allow_ff: false
So now with this change, whenever I add a commit to master branch directly or any PR gets merged to master branch directly then master branch will be merged to dev branch automatically right?