简体   繁体   中英

How do I allow just 1 user to push to a branch in GitHub?

在此处输入图片说明

I would like for only 1 user to be able to push (force push and regular push) to a certain branch, and everyone else to not have permissions to push.

These are the permissions I set (with my user listed under "Restrict who can push to matching branches". However, when I try to force push I get a branch protected error.

First, you will want to make the branch pull request only. The screenshot you showed will get you that.

After that is done, I guess you can make one of the CI checks to be "checking if the author of the pull request is in the whitelist".

Then, in the "require status check to pass before merging", add the check mentioned in the last step.

Now, no one can ever make changes to this branch unless your CI says "yes, this author is allowed to make changes in this branch"

As for if you want to automatically merge branches that pass the whitelist check, I will not suggest doing it, but if you want to, there are many GitHub apps that can do that, and you can also make a very minimal GitHub app yourself using the GitHub APIs.

Actually, that still doesn't allow the user to force push.

Since Dec. 4th 2019 , there is a way to grant all users with push access the ability to force-push to a protected branch by enabling Allow force pushes .

If the CI user has push access to (the protected branch) master , it will be able to force push.

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