Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 20

CODEOWNERS per branch

We'd like to have CODEOWNERS set up only for our master branch (we don't want pull requests to other branches to necessarily be automatically assigned a reviewer), but I can't seem to figure out how to do that.

 

This page https://help.github.com/articles/about-codeowners/ states "Each CODEOWNERS file assigns the code owners for a single branch in the repository. Thus, you can assign different code owners for different branches"

 

How would I go about having different CODEOWNERS settings between branches? Thanks!

19 Replies
Community Manager
Message 2 of 20

Re: CODEOWNERS per branch

Hi @joelbeckham,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the How to use Git and GitHub board.

Let us know if you have any questions or if we can help with anything else.

Cheers!

Be sure to click Accept as Solution to mark helpful posts to help other users locate important info. Also, don't forget to give Kudos for great content!

Ground Controller Lvl 1
Message 3 of 20

Re: CODEOWNERS per branch

Can you provide some link to that "other discussion board" as I am also interested to be able to have different reviewers for different branches. I cannot find that answer.

Community Manager
Message 4 of 20

Re: CODEOWNERS per branch

This topic is already on "the other board", How to use Git and GitHub. It was moved, not copied 😀

Community Manager
Message 5 of 20

Re: CODEOWNERS per branch

Apologies that this seems to have not gotten answered when it was originally posted. The contents of the `CODEOWNERS` file on the branch in question governs the behavior of the feature for that branch. So if `CODEOWNERS` says one thing on `master` and `dev` but something else on `test` then the feature will follow the first set of rules for PRs to be merged into `master` or merged into `dev` but follow the different rules for PRs to be merged into `test`.

 

I hope that helps!

Copilot Lvl 2
Message 6 of 20

Re: CODEOWNERS per branch

I seem to be maybe missing something or maybe just need a clarification. Does the CODEOWNERS file apply to repo owners/admins?

 

Reason I ask is because in my repository I have a master and a dev branch and set it up as suggested in this thread. Both branches have the CODEOWNERS file in a /.github directory. In the master branch codeowners file I but my user id as the only review using the '*' syntax (e.g. "*   @aspea002"). Had a colleague of mine test it out by opening a PR between master(base) and dev and my name shows up in the reviewers section. So to test things out further I then created/updated the dev branch with its own CODEOWNERS file contents to have it reference my colleagues ID. I then tried opening a PR with a dev2 branch against dev(master) however I do not see his name being added to the Reviewers section. I do so for a brief moment the words "Loading reviewers..." but then it just stops and shows "No Reviewers-select one".

 

As I mentioned earlier, is this because I am a repo admin. I have tried different settings on the DEV branch everything from not having the DEV protected branch setting turned on to adding the protected branch settings with combinations of requiring a reviewer and codeowner review required and nothing has changed. Also forgot to mention this is all done with my colleague permission on the repo set to WRITE.

 

Any help would be appreciated.

Moderator
Message 7 of 20

Re: CODEOWNERS per branch

Hi @prowler0305,

The CODEOWNERS file should apply to all users with write permissions. Is the repo you're working in public by chance? If so, could you share a link to it so we can look closer? If it's a private repo, I'd recommend working with private support for a solution.

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Ground Controller Lvl 1
Message 8 of 20

Re: CODEOWNERS per branch

I am looking at using CODEOWNERS as part of a project with a large number of developers.    I want to implement a separate review policy for "master" and "develop" branches.      I understand how to set this up initially, but I don't understand how one  prevents subsequent merges from blending the two policies.    Some manual experiments on a toy repository show that  a merge from develop to master updates the CODEOWNERS policy on master and therefore undoes the intended policy there.

 

Is this just something that I should "not want to do"?    It seems like such a nice approach otherwise.   But the dearth of similar questions being asked on this topic suggests I'm alone in really wanting to exploit the per-branch aspect of this feature.

 

Copilot Lvl 2
Message 9 of 20

Re: CODEOWNERS per branch

Not clear to me either how to prevent merges between branches overweite the CODEOWNERS file

 

Do we need to put it in `.gitignore` and change it manually ?

Community Manager
Message 10 of 20

Re: CODEOWNERS per branch

Hi @mderazon,


Merging a branch into master overwrites the CODEOWNERS rules for master. This is the expected behavior. `git merge` takes all the changes that were made to the source branch since the source and destination diverged and applies them to the destination branch. So if `CODEOWNERS` changes on the source branch, that change will be applied to the destination branch when they are merged.

 

There are multiple ways this could be managed:

 

  • Instead of merging, one could cherry pick only the changes that do not touch `CODEOWNERS`
  • One could create a merge script that would do the merge and then reset `CODEOWNERS` to a known-good state

 

Hope this is helpful. 

Be sure to click Accept as Solution to mark helpful posts to help other users locate important info. Also, don't forget to give Kudos for great content!