Restrict certain GitHub users to merge branches
Solution 1
No. The only way to prevent things like this are git's internal pre-commit or update hooks. Those hooks get called before to push is accepted.
GitHub itself doesn't support pre-commit or update hooks. Only web hooks are supported. But these are called after the push. So too late to prevent certain types.
Solution 2
If your repository is under an organization on Github, you can add the developers to a read-access team. That way they can see and check out the repository but can't commit to it. They can also fork the repository, which lets them do their work in their fork then submit pull requests to get their work committed to the main repository.
You can then grant write access to only certain developers who will be in charge of reviewing and merging pull requests.
Solution 3
bitbucket supports permissions per branch which would help you prevent merges to your branches. I miss that feature on github
Solution 4
NO
You may be thinking this because of the "Merge Changes" button of Github on a Pull Request. But that is just a convenience thing. For example, if there are conflicts, that button is disabled, and you'd have to manually merge changes on your machine and Push them to Github.
So, if a user can Push changes to a branch, how would you stop him to merge another branch on his machine, and Push it? Since that kind of restriction is not there in Github afaik, you won't be able to accomplish this.
Oh, but you can always ask your users politely not to merge branches ;).
Related videos on Youtube
HitOdessit
Currently I'm working as Mobile Engineering Lead at RingCentral. My LinkedIn profile: http://ua.linkedin.com/in/valerybogdanov
Updated on June 27, 2022Comments
-
HitOdessit almost 2 years
Is it possible to restrict certain git users to merge git branches on GitHub? I want to let users commit, pull and push changes in current branch, switch to another existing branch, but do not allow to merge branches. Is it possible on GitHub.com or standalone git repository?
-
HitOdessit about 12 yearsWait, git itself always know when merging two different branches, and reftects this in log. And I don't see any theoretical reasons to implement some kind of "merge-branches-permission" in git. Yes, I agree whan such limitation most likely should be implemented in git client app, not on GitHub servers.
-
Sailesh about 12 yearsGit is a distributed source control system. This means that when you clone any repo to your machine, you have complete authority on that code. Github only acts as a hosting service. So putting client side constraint would definitely be wrong. And I am not sure how this can be a part of Github.
-
danielricecodes almost 9 yearsIs this a feature of Github Enterprise?