每当有任何更改提交给 master 时,我们希望自动从 master merge 到另一个长期存在的分支(目前,这是一个手动过程,人们忘记了)
我明白,由于 merge 冲突,这可能并不总是可能的,但如果可能的话,我们希望它自动发生。
这可能吗?
最佳答案
自 2019 年 8 月 13 日起您可以使用 GitHub Actions
此方法会将您的分支与主分支 merge ,而无需手动创建 pull 请求。
只需在您的存储库中使用以下内容创建 .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”行以调整计划
此外,不要忘记在您的存储库的“操作”页面上启用此工作流。您也可以手动运行它。如果 merge 失败,您将收到来自 GitHub 的电子邮件。
关于git - GitHub 可以自动 merge 分支吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35445186/