How to limit Github codeowners file to specific branches only?

Viewed 4620

I'm using CODEOWNERS file on Github to setup automatic pull-request reviewers based on files/folders. The system works well and reviewers get added automatically to pull-requests.

However, I want to limit this setup just for release branches, and not for private branches. When a private branch is taken off of a release branch, it also gets the CODEOWNERS file and in turn all the "automatic reviewers for pull-requests" setup.

Is there a way to make sure that the CODEOWNERS file applies only to specific branches? Or a way to make sure that this particular file doesn't get synced to other branches at all?

2 Answers

You can enforce pull request reviews from CODEOWNERS based on branches.

In your Repo, Go to: Settings -> Branches -> Add Rule -> Apply rule to <your branch> .
Then mark Require pull request reviews before merging -> Require review from Code Owners

This will make sure the rule only applies to that specific branch

Add .gitignore in ALL your branches and make sure it's an exact copy that includes CODEOWNERS (.gitignore file has a line that specifies CODEOWNERS file) then modify all the other branches with the respective codeowners you want (ex. prod branch with OPS codeowners/approvers & dev branch with dev codeowners/approvers)

Related