GitHub可以自动合并分支吗?

时间:2016-02-16 23:39:06

标签: git github

我们希望每当任何更改提交给master时,都会自动从master转移到另一个长期分支(此时,这是一个手动过程而且人们忘记了)

我理解由于合并冲突,可能并非总是可能,但如果可能的话,我们希望它自动发生。

这可能吗?

5 个答案:

答案 0 :(得分:10)

据我了解你的问题,可以在git-automatic-merges-with-server-side-hooks找到一篇非常好的博文,包括脚本。

答案 1 :(得分:3)

它将在2021年上市。

本地GitHub自动合并是2天前在GitHub Universe上引入的。

自动合并请求请求功能将从下周开始面向私有存储库和企业客户提供;对于公共存储库,它将处于公开Beta版。

Source

虽然这可能不仅仅是用例所需要的,但它可以与GitHub Actions一起使用,以更轻松地到达那里。

答案 2 :(得分:2)

您现在https://github.com/features/actions可以使用Github动作

答案 3 :(得分:2)

我已经使用https://github.com/marketplace/actions/merge-pull-requests一段时间了,并且效果很好。在该页面中,您有如何使用它的说明。

如果您需要更具体的工作流程,也可以尝试https://mergify.io/

答案 4 :(得分:1)

自 2019 年 8 月 13 日起您可以使用 GitHub 操作

此方法会将您的分支与主分支合并,而无需手动创建拉取请求。

只需使用以下内容在您的存储库中创建 .github/workflows/automerge.yml 文件:

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

  • 将“github_username”替换为您的 GitHub 用户名
  • 将“github.com/username/repo.git”替换为您的 GitHub 存储库路径
  • 将“long-lived_branch_name”替换为您的分支名称
  • 用你的主分支名称替换“master”
  • 编辑“cron”行以调整时间表

此外,不要忘记在您的存储库的“操作”页面上启用此工作流程。您也可以手动运行它。如果合并失败,您将收到来自 GitHub 的电子邮件。