10

I am using branching to create and deploy custom instances of out platform. 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.

Is there any easy way to forbid merging back into the master? Or at least requiring some --force flag?

4

3 回答 3

2

您可以通过禁止任何人推送主分支来确保不会从其他分支合并到主分支。一个有权威的人可以做到这一点。Gitolite 可以让您微调对分支的访问。您还可以编写自己的服务器端挂钩并拒绝更新主分支,除非您是特定用户。

于 2011-11-17T01:21:18.140 回答
1

Git 非常乐意使用多个远程存储库。

我建议为每个自定义实例使用一个远程存储库。这不会改变您的工作流程,因为 Git 可以将任意两个分支合并在一起,而不管其来源如何。

要使用“主遥控器”中的错误修复更新“自定义实例”,您需要输入类似

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

main您所指的远程存储库在哪里master(我更改了名称以避免分支和远程之间的混淆)

对于您的本地分支,不要指定main为远程跟踪分支,而是指定一个特定于实例的远程。即每个自定义实例一个远程存储库。

要将更改推送到您的自定义实例,请使用

git push

在极少数情况下,您需要将更改上游推送到“主”分支使用

git push main
于 2011-11-21T21:04:08.023 回答
0

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

于 2011-11-21T11:55:25.253 回答