26

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?

1
  • 11
    Almost 4 years later and there is no answer to this. Even though GithHub docs act like it should be possible: "Each CODEOWNERS file assigns the code owners for a single branch in the repository.". This is ridiculous.
    – Akaisteph7
    Commented Aug 17, 2022 at 15:50

3 Answers 3

5

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

4
  • 11
    I should've been more clear. The option you mentioned only to specify if CODEOWNERS approval is mandatory or not. The reviewers still get added to PRs for private branches and Github sends unnecessary notification emails.
    – ronakg
    Commented Apr 30, 2020 at 22:40
  • 4
    Hey! Did you find any solution for this? Commented Mar 14, 2022 at 16:58
  • Nope. Still no solution to this problem.
    – ronakg
    Commented Feb 15, 2023 at 20:55
  • 1
    This doesn't answer the question. I would love to know the answer to this.
    – nick
    Commented Sep 11, 2023 at 11:12
0

It does work exactly like (s)he said add it to all branches local and remote the only problem is you manually need to update codeowners of each remote branch in git web interface as

-4

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)

1
  • 1
    This doesn't work because CODEOWNERS needs to be one the remote repo. In your exemple, it is only on the local one Commented Jan 14, 2020 at 23:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.