Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does github allow pre-receive hooks?

Tags:

git

github

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 (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.

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

like image 486
Jason Waldrip Avatar asked Jun 02 '12 18:06

Jason Waldrip


People also ask

What is pre-receive Hook declined in git?

Your commits were rejected by the pre-receive hook of that repo (that's a user-configurable script that is intended to analyze incoming commits and decide if they are good enough to be accepted into the repo). It is also a good idea to ask that person to update the hook, so it would print the reasons for the rejection.

What is git pre-commit hook?

The pre-commit script is executed every time you run git commit before Git asks the developer for a commit message or generates a commit object. You can use this hook to inspect the snapshot that is about to be committed.

How do you test a pre received hook?

A pre-receive hook, like a pre-push hook, must read its standard input, one line at a time, checking each group of parameters supplied on that line. If the hook exits with a nonzero return, the entire push is rejected (from the server's side).


2 Answers

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.
like image 162
GoZoner Avatar answered Sep 20 '22 09:09

GoZoner


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 (i.e. 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!

like image 40
brntbeer Avatar answered Sep 23 '22 09:09

brntbeer