简体   繁体   English

防止git merge到master分支

[英]preventing git merge to master branch

I am using branching to create and deploy custom instances of out platform. 我正在使用分支来创建和部署out平台的自定义实例。 These instances usually start as a branch from the 'master' branch, get customized somewhat, get deployed into testing and production, and finally archived. 这些实例通常从“主”分支开始,在某种程度上进行定制,部署到测试和生产中,最后归档。

If new features or bug fixes are added into the master I would like to be able to fetch/merge them into my project instances (branches), but I almost never want to merge back changes from the branches to the master. 如果将新功能或错误修复添加到主服务器中,我希望能够将它们提取/合并到我的项目实例(分支)中,但我几乎不想将更改从分支合并到主服务器。 This occurred recently by mistake and has created some serious headaches. 最近这种情况发生了错误,并造成了一些严重的问题。 A git pull to update a repository merged everything into the master branch and then was pushed back into the main repo. 更新存储库的git pull将所有内容合并到主分支中,然后被推回到主repo中。

Is there any easy way to forbid merging back into the master? 是否有任何简单的方法可以禁止合并回主人? Or at least requiring some --force flag? 或者至少需要一些--force标志?

You can ensure no merging into the master from other branches by forbidding anyone to push the master branch. 您可以通过禁止任何人推送主分支来确保不与其他分支合并到主服务器。 A person with authority can do that. 有权威的人可以做到这一点。 Gitolite is something that allows you to finely tune access to branches. Gitolite允许您精细调整对分支的访问。 You can also write your own server side hooks and reject updating of the master branch unless you are a specific user. 除非您是特定用户,否则您还可以编写自己的服务器端挂钩并拒绝更新主分支。

Git is quite happy to work with multiple remote repositories. Git非常乐意使用多个远程存储库。

I would recommend using one remote repository for each custom instance. 我建议为每个自定义实例使用一个远程存储库。 This would not change your workflow, as Git can merge any two branches together regardless of origin. 这不会改变您的工作流程,因为Git可以将任意两个分支合并在一起,而不管其来源如何。

To update a "custom instance" with bug fixes from your "master remote" you'd type something like 要使用“主遥控器”中的错误修复程序更新“自定义实例”,您需要键入类似的内容

git checkout <custom-branch>
git fetch main
git merge main/master

where main is the remote repository you are referring to as master (I changed the name to avoid confusion between a branch and a remote) main是您称为master的远程存储库(我更改了名称以避免分支和远程之间的混淆)

For your local branches, do not specify main as the remote tracking branch, instead specify an instance-specific remote. 对于本地分支, 请不要main指定为远程跟踪分支,而是指定特定于实例的远程分支。 ie one remote repository per custom instance. 即每个自定义实例一个远程存储库。

To push changes to your custom instance, use 要将更改推送到自定义实例,请使用

git push

In the rare case where you need to push changes upstream to the "master" branch use 在极少数情况下,您需要将更改上游推送到“主”分支使用

git push main

如果你只是想避免合并到master中,你可以使用pre-merge hook来禁止它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM