Can GitHub automatically merge branches?

You can use GitHub Actions since Aug 13, 2019

This method will merge your branch with the master without the requirement to create pull requests manually.

Just create .github/workflows/automerge.yml file in your repo with this content:

name: Automerge

on:
  workflow_dispatch:
  schedule:
    # You can setup schedule here
    - cron: '0 0 * * *'

env:
  # replace "github_username" with your GitHub username
  # replace "github.com/username/repo.git" with your GitHub repo path
  # do NOT replace ${{secrets.GITHUB_TOKEN}}, GitHub will take care of it
  MY_REPO: https://github_username:${{secrets.GITHUB_TOKEN}}@github.com/username/repo.git

  # replace "long-lived_branch_name" with your branch name
  MY_BRANCH: long-lived_branch_name

  # replace it with the path to master repo
  MASTER_REPO: https://github.com/username/master_repo.git

  # replace "master" with your master branch name
  MASTER_BRANCH: master

jobs:
  merge:
    runs-on: ubuntu-latest

    steps:
    - name: Merge with master
      run: |
        git clone ${{env.MY_REPO}} -b ${{env.MY_BRANCH}} tmp
        cd tmp
        git config user.name "Automerge Bot"
        git config user.email "bot@example.com"
        git config pull.rebase false
        git pull ${{env.MASTER_REPO}} ${{env.MASTER_BRANCH}}
        git push

  • replace “github_username” with your GitHub username
  • replace “github.com/username/repo.git” with your GitHub repo path
  • replace “long-lived_branch_name” with your branch name
  • replace “master” with your master branch name
  • edit “cron” line to adjust the schedule

Also, don’t forget to enable this workflow on the “Actions” page of your repo. You can run it manually too. You’ll receive an e-mail from GitHub if merge was failed.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)