简体   繁体   中英

Does github allow pre-receive hooks?

Does GitHub allow for pre-receive or update hooks?

What I would be looking to do is to prevent the primary branches from being pushed to (ie 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.

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

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.

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.

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.

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

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!

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-push hook script for everyone to install into their .git/hooks directory. (I did something similar recently by insisting everyone run git config branch.autosetuprebase always which implicitly changes git pull to git pull --rebase to eliminate needless merges when local unpushed commits exist)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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