git github 是否允许预接收钩子?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10864903/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:59:45  来源:igfitidea点击:

Does github allow pre-receive hooks?

gitgithub

提问by Jason Waldrip

Does GitHub allow for pre-receive or update hooks?

GitHub 是否允许预接收或更新挂钩?

What I would be looking to do is to prevent the primary branches from being pushed to (i.e. master, hotfix, develop) and require that they be merged via a GitHub pull request. This is a private repo so GitHub style forking is not an option.

我想要做的是防止主分支被推送到(即 master、hotfix、develop),并要求通过 GitHub 拉取请求合并它们。这是一个私人仓库,所以 GitHub 风格的分叉不是一种选择。

Any advice on how to accomplish this would be of great help.

关于如何实现这一点的任何建议都会有很大帮助。

采纳答案by GoZoner

Only people that you have listed a 'collaborators' can push to a Github hosted repository. See the repository's 'admin' page to add collaborators. Everybody else needs to submit a 'pull request' to get their additions accepted by the repository's administrator. See Github Access Permissions. (There aren't per-branch access permissions.) So, in order to accomplish your goal, you don't need hooks; what you need is already built in.

只有您列出了“合作者”的人才能推送到 Github 托管的存储库。请参阅存储库的“管理”页面以添加协作者。其他所有人都需要提交“拉取请求”才能让存储库管理员接受他们的添加。请参阅Github 访问权限。(没有每个分支的访问权限。)所以,为了实现你的目标,你不需要钩子;你需要的已经内置了。

Two Notes:

两个注意事项:

  1. private Github repositories can have multiple contributors
  2. it would be unusual for Github to support pre-receive hooks (or any other server hooks) given that hooks contains arbitrary code.
  1. 私有 Github 存储库可以有多个贡献者
  2. 鉴于钩子包含任意代码,Github 支持预接收钩子(或任何其他服务器钩子)是不寻常的。

回答by brntbeer

Though GitHub itself doesn't allow pre-receive hooks, GitHub Enterprise version 2.6 does include pre-receive hook support. More information about it can be found here: https://help.github.com/enterprise/admin/guides/developer-workflow/using-pre-receive-hooks-to-enforce-policy/. These are instance wide pre-receive hooks to prevent any information to be pushed into any repositories.

尽管 GitHub 本身不允许预接收挂钩,但 GitHub Enterprise 2.6 版确实包含预接收挂钩支持。关于它的更多信息可以在这里找到:https: //help.github.com/enterprise/admin/guides/developer-workflow/using-pre-receive-hooks-to-enforce-policy/。这些是实例范围的预接收钩子,以防止将任何信息推送到任何存储库中。

What I would be looking to do is to prevent the primary branches from being pushed to (i.e. master, hotfix, develop) and require that they be merged via a GitHub pull request.

我想要做的是防止主分支被推送到(即 master、hotfix、develop),并要求通过 GitHub 拉取请求合并它们。

However, to this point, you can configure GitHub or GitHub Enterprise repositories with protected branches. What this does is prevent the branch from being deleted, force pushed, only certain people or teams can merge, or a status check is required to be passing before a merge is allowable. Please see https://help.github.com/articles/about-protected-branches/for more information!

但是,到目前为止,您可以使用受保护的分支配置 GitHub 或 GitHub Enterprise 存储库。这样做是为了防止分支被删除,强制推送,只有某些人或团队可以合并,或者在允许合并之前需要通过状态检查。请参阅https://help.github.com/articles/about-protected-branches/了解更多信息!

回答by Jay Allen

If you're collaborating with a trusted team (which I assume you are since it's a private repo) and you want to implement this simply to keep people from accidentally violating your standard operating procedures out of pure habit, the best thing to do is distribute a custom pre-pushhook script for everyone to install into their .git/hooksdirectory. (I did something similar recently by insisting everyone run git config branch.autosetuprebase alwayswhich implicitly changes git pullto git pull --rebaseto eliminate needless merges when local unpushed commits exist)

如果你正在与一个值得信赖的团队合作(我假设你是,因为它是一个私人回购)并且你想实施这个只是为了防止人们出于纯粹的习惯意外违反你的标准操作程序,最好的办法是分发pre-push每个人都可以安装到他们的.git/hooks目录中的自定义钩子脚本。(我做了类似的事情最近大家都坚持跑git config branch.autosetuprebase always含蓄地改变git pullgit pull --rebase时当地unpushed提交存在,以消除不必要的合并)

If for some reason that doesn't work, I find that the threat of losing committer rights after the fact is usually an effective mechanism for keeping people honest.

如果由于某种原因不起作用,我发现事后失去提交者权利的威胁通常是保持人们诚实的有效机制。