HitOdessit
HitOdessit

Reputation: 7256

Restrict certain GitHub users to merge branches

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?

Upvotes: 19

Views: 16571

Answers (6)

New Alexandria
New Alexandria

Reputation: 7324

Yes, GitHub now supports this natively. Sometime in 2020-2021(?) they began to support Code Owners, which are GitHub users from who a PR review is required before a merge is allowed.

  1. This is branch-specific behavior
  2. This requires a user or GitHub team be referenced
  3. This targets one or more file paths within the repo

Upvotes: 1

Michael Melanson
Michael Melanson

Reputation: 1335

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.

Upvotes: 9

sebastian serrano
sebastian serrano

Reputation: 1057

bitbucket supports permissions per branch which would help you prevent merges to your branches. I miss that feature on github

Upvotes: 6

Philip Durbin
Philip Durbin

Reputation: 4082

I'm not sure what "standalone git repository" means, but gitolite might give you what you want:

"Example 2, one repo, but different levels of access to different branches and tags for different developers" -- http://sitaramc.github.com/gitolite/why.html

See also Git: Teamwork across branches without Push Permission

Upvotes: 0

iltempo
iltempo

Reputation: 16012

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.

Upvotes: 8

Sailesh
Sailesh

Reputation: 26197

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 ;).

Upvotes: 1

Related Questions