github - enable branch lock

。_饼干妹妹 提交于 2019-12-10 10:27:12

问题


As a GitHub administrator, I would like to lock a particular branch in GitHub for all users. For e.g. if I do not want anyone to push to Master/Production or a Project branch, how can I do that.

Instead of using any client side hooks, is there a way to lock a branch on GitHub server directly ? Are there any third party tools/api's/scripts which can help achieve this ?


回答1:


The easiest solution is to have that branch in its own repo (for which no collaborators) are declared.

Otherwise, GitHub doesn't provide any native "branch protection" feature, as mentioned in "How to protect “master” in github?"

You could setup a webhook which on a push event can refuse the push if the branch has a given name.

An example would be terite/pull-to-master which protects master:

if (json.ref != 'refs/heads/master')
  return cb([200, 'Skipping, not master']);

This is not a client-side hook, but it does require a client to listen to the JSON payload of the push event in order to react to it.




回答2:


@Saurabh I have done the similar thing according to your requirement on **GITHUB**. 
Explaning below

-> Navigate to settings
-> Navigate to Branches
-> Tap on Add Rule
-> Under rule setting. Tick the **Require Pull request review before merging** 

What the above steps does that it applied the lock on say **Master** branch so that no collaborators can push the code on master, the code only merged using pull request. 

Attaching the screnshot below. 



来源:https://stackoverflow.com/questions/29336828/github-enable-branch-lock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!