Q: Is there a way to allow only the branch creator to push on it in Github? 
*

*I have a Github organization.

*I created a repository and a team to work on it.

*I want to restrict push to any branch to it's creator by the default.

*So that no one can push to someone's else branch.

*Is there any method to do that other than adding rule for every branch manually?


I tried to add rules manually, but it's time consuming cause there are many people joining the team.
Update:


*

*I went to my organization -> teams.

*Selected the team, went to members, selected a member.

*Clicked on "manage access" next to one repository, clicked "edit".

*Set "Base permissions" to "Write".

*Set "Repository creation" to "Disabled".

*Everything else is left unchecked.


A: I won't comment on whether or not this is a good idea.
Suffice to say I was annoyed once leading me to create the following update hook to apply to the canonical repo (note however that Github does not allow custom update hooks so you're out of luck there):
#!/usr/bin/env python
import os
import re
import sys
from pathlib import Path
from subprocess import check_output


branch = sys.argv[1]
old_commit = sys.argv[2]
new_commit = sys.argv[3]
zero = "0000000000000000000000000000000000000000"
branch_pattern = 'feature/.+'


def get_author(commit):
    return str(check_output(['git', '--no-pager', 'show', '-s', "--format='%an'", commit]).strip(), 'utf-8')


def allow(message=None):
    if message:
        print(message)
    exit(0)


def deny(message=None):
    if message:
        print(message)
    exit(1)


# if this isn't a feature branch bail
if not re.match(branch_pattern, branch):
    allow()

# if the update is a delete bail
if new_commit == zero:
    allow("update: deleting branch '%s': OK" % branch)

# if this is the first commit on the branch bail
if old_commit == zero:
    allow("update: creating branch '%s': OK" % branch)

branch_log = Path('.git', 'logs', 'refs', 'heads').joinpath(*branch.split(os.path.sep))
with open(branch_log, 'r') as log:
    first_commit = log.readline(81).split(sep=' ', maxsplit=1)[1]

branch_author = get_author(first_commit)
new_commit_author = get_author(new_commit)

print("update: branch = '%s'; branch author = %s; commit author = %s" % (branch, branch_author, new_commit_author))

if new_commit_author == branch_author:
    allow("update: commit author == branch author: OK")
else:
    deny(
        "update: branch author != commit author: REJECTED\n"
        "update: create a branch for your changes from the tip of %s and request a pull instead"
        % branch
    )


A: Organization owners and people with admin permissions for organization-owned repositories can enforce branch restrictions so that only certain users or teams are able to push to a protected branch.
For more info, see here
