You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何保护分支合并:仅允许Development分支合并至Main分支

配置分支保护规则限制仅从development分支推送至Main分支

以下以主流Git托管平台为例完成权限管控配置:

GitHub平台操作步骤

  • 打开目标仓库的「Settings」页面,选择左侧菜单栏的「Branches」选项
  • 在「Branch protection rules」区域点击「Add rule」
  • 在「Branch name pattern」输入框中填写 Main(匹配你的主分支名称)
  • 勾选Require a pull request before merging,强制所有对Main分支的修改必须通过Pull Request完成
  • 找到Restrict which branches can be merged into matching branches选项,勾选后在输入框中填写 development,指定仅允许从该分支发起的PR合并到Main分支
  • 可选:勾选Require branches to be up to date before merging,确保合并前development分支与Main分支代码同步,减少冲突
  • 完成配置后点击「Create」保存规则

GitLab平台操作步骤

  • 进入仓库的「Settings」-「Repository」页面,找到「Protected branches」区域
  • 点击「Protect a branch」,选择Main分支
  • 在「Allowed to merge」中设置允许合并的角色,同时找到「Allowed branches」选项,添加development作为唯一允许合并到Main的来源分支
  • 保存配置即可

配置完成后,alpha、beta分支无法直接推送或通过PR合并到Main分支,只有development分支的修改可以通过合规流程合并到Main分支。

内容的提问来源于stack exchange,提问作者Yamilet Mendoza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 18:52:01