git 禁用推送到 GitHub 上的特定分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18520618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable push to specific branches on GitHub
提问by Huafu
I have some Git private repositories on a GitHub company account, and I don't want anybody to push on some specific branches (like master, develop and beta or by pattern). I also tried to define some hooks but I want this to be done on GitHub and not done with a pre-push hook on the clients.
我在 GitHub 公司帐户上有一些 Git 私有存储库,我不希望任何人推动某些特定分支(例如 master、develop 和 beta 或按模式)。我也尝试定义一些钩子,但我希望这在 GitHub 上完成,而不是在客户端上使用 pre-push 钩子来完成。
So to explain my problem simply, I want:
所以简单地解释我的问题,我想:
git push origin develop
to be refused by the server (which is GitHub) because of the branch name, but I do not want a client check by pre-push hook, I really want GitHub to do the check and refuse it.
由于分支名称而被服务器(即GitHub)拒绝,但我不想通过 pre-push hook 进行客户端检查,我真的希望 GitHub 进行检查并拒绝它。
Also if it's possible to allow only certain users to do so, but disabling it for everybody would be enough at first.
此外,如果可以只允许某些用户这样做,但首先为每个人禁用它就足够了。
采纳答案by Huafu
Ok I got the answer from IRC after a long chat. I'll have to work with forks and pull requests, or add pre-push hooks on each dev's machine since GitHub doesn't allow per branch permissions neither pre-publish canceling hooks. Here is a part of the answers I got:
好的,经过长时间的交谈,我从 IRC 得到了答案。我将不得不处理分叉和拉取请求,或者在每个开发人员的机器上添加预推送挂钩,因为 GitHub 不允许每个分支权限,也不允许预发布取消挂钩。以下是我得到的部分答案:
Fork the repository. then the developer can work on their own version of the repository, and doesn't have to worry about committing to the wrong branch. And then someone upstream can always merge into whatever branch should be committed into.
Yeah but we're a company and we don't want that all our devs have forks
Why not?
Well they should be able to push their branch on a common repo to work with some other devs on the same feature for example.
Have a read through https://help.github.com/articles/using-pull-requests. You can still send patches around between multiple forks. This is the model that git was built on
I know but I want to be able to see quickly in a central way the actual work on any feature/hotfix, ...
To cut a long story short: GitHub doesn't support per-branch permissions
分叉存储库。然后开发人员可以在他们自己的版本库上工作,而不必担心提交到错误的分支。然后上游的某个人总是可以合并到应该提交的任何分支中。
是的,但我们是一家公司,我们不希望我们所有的开发人员都有分叉
为什么不?
好吧,他们应该能够将他们的分支推送到一个公共存储库上,以便与其他一些开发人员一起使用相同的功能。
通读一下https://help.github.com/articles/using-pull-requests。您仍然可以在多个分叉之间发送补丁。这是构建 git 的模型
我知道,但我希望能够以集中方式快速查看任何功能/修补程序的实际工作,...
长话短说:GitHub 不支持每个分支的权限
回答by Slavik Meltser
I know that this post is pretty old, but I believe that it may still help for some of you who are looking for an answer.
我知道这篇文章已经很旧了,但我相信它可能仍然对你们中的一些正在寻找答案的人有所帮助。
Well, now it is possible on GitHub.
Recently GitHub have introduced the Protected Branchesfeature, which makes it possible:
好吧,现在可以在 GitHub 上实现。
最近 GitHub 推出了Protected Branches功能,这使得它成为可能:
Protected branches block several features of Git on a branch that a repository administrator chooses to protect. A protected branch:
- Can't be force pushed
- Can't be deleted
- Can't have changes merged into it until required status checks pass
- Can't have changes merged into it until required reviews are approved
- Can't be edited or have files uploaded to it from the web
受保护的分支在存储库管理员选择保护的分支上阻止 Git 的几个功能。受保护的分支:
- 不能强推
- 无法删除
- 在所需的状态检查通过之前不能将更改合并到其中
- 在所需的获得批准之前,不能将更改合并到其中
- 无法编辑或从网络上传文件
Good luck.
祝你好运。
回答by Oliver Matthews
The hooks you are looking for are pre-receive
and update
- the former is run once per push, the latter once per branch per push; but importantly, these are hooks on the serverside.
您正在寻找的钩子是pre-receive
和update
- 前者每次推送运行一次,后者每次推送每个分支运行一次;但重要的是,这些是服务器端的钩子。