GitHub – How to Restrict Master Branch/Pull Request Access

github

I'd like to restrict write access to the master branch in a organization repository to its owner (namely me). This would enforce all contributors to make a branch instead of committing directly to master. If possible, I would also like to restrict access to approving pull requests to only me.

I did some research and came across GitHub protected branches, and I believe it might be the solution. But there are too many options to understand. The linked help page didn't help me either.

Best Answer

Yes, you will want to look into the Protected Branch settings.

If others need to do their work on another branch instead of working directly off master, check the following box:

Require pull request reviews before merging
When enabled, all commits must be made to a non-protected branch and submitted via a pull request with at least one approved review and no changes requested before it can be merged into master.

To then also limit who can approve it should be by selecting this checkbox:

Restrict who can push to this branch
Specify people or teams allowed to push to this branch. Required status checks will still prevent these people from merging if the checks fail.

By default that will restrict it to admins only. If the repo has other admins listed then you'll want to get that sorted out because the included owners are:

Organization and repository administrators - These members can always push.