github codeowners for each branch

2.3k Views Asked by At

Github says I can assign different code owners for different branch.
but how?
Is there any way for having different file for different branch without any conflict on merging??

please let me know how I can do it.

https://docs.github.com/en/enterprise-cloud@latest/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-file-location

Each CODEOWNERS file assigns the code owners for a single branch in the repository. Thus, you can assign different code owners for different branches, such as @octo-org/codeowners-team for a code base on the default branch and @octocat for a GitHub Pages site on the gh-pages branch.

1

There are 1 best solutions below

0
On

Github says I can assign different code owners for different branch.
but how?

Exactly that — by having different files in different branches.

Is there any way for having different file for different branch without any conflict on merging??

Well, no. But you can configure your local repository to work around the conflicts.

First, you can use builtin merge driver "ours"; see https://stackoverflow.com/a/59503455/7976758 found in https://stackoverflow.com/search?q=%5Bgit%5D+exclude+file+merge

echo .github/CODEOWNERS merge=ours >> .gitattributes
git config merge.ours.driver true

This doesn't completely exclude the file from merge but lower the frequency of conflicts. If you want to completely exclude it and always update it manually you can do

git checkout HEAD .github/CODEOWNERS

after merge. You can try to automate this in a post-merge hook. Something like

echo '#! /bin/sh
git checkout HEAD .github/CODEOWNERS
' > .git/hooks/post-merge
chmod u+x .git/hooks/post-merge