The easy & exciting git collaboration plugin you need

Daniel Trugman
D-Bits
Published in
3 min readJul 9, 2022

Have you ever shared a git repository with other teams? Did someone ever change your code without you knowing? Keep on reading for a life-changing method to effectively enforce healthy coordination between code owners!

There’s a lot of discussion going on about monorepos vs. polyrepos. In case you haven’t heard those concepts before, monorepo means using a single repository where projects coexists next to each other, while polyrepo means using a repository per project. In practice, this is far from a dichotomy, and there’s a wide range of options for teams to choose from.

I personally never worked in a company where there’s actually a single repository for the entire engineering team. Yet I definitely had my share of collaboration over the same code repository with multiple other teams.

For example, in my previous job, we had a product that supported Linux, Windows and MacOS. We had four different teams, three platform teams for each of the aforementioned platforms (I was leading the Linux team) and a fourth one that was responsible for cross-platform code. Because we were sharing a lot of code between the teams and the products, we ended up using a single repository for all four teams.

I cannot overstate the importance of clearly communicating code changes in a shared repository. However, no matter how you try, people are going to push code that will have undesired and unexpected affects without CC’ing you on a CR. Sometimes it’s an honest mistake and other times it’s just because that’s how they manage to deliver their features on time. Even though I truly believe we had a superb work environment, you simply can’t avoid that. Amazon’s founder, Jeff Bezos, used to say:

“Good intentions never work, you need good mechanisms to make anything happen”, Jeff Bezos

Lucky for us, there is something that can do just that. The Code Owners plugin is a great mechanism to enforce those healthy collaboration practices in your git repository. It was introduced into Github a few years ago, Gitlab and Gerrit soon followed suit and 3rd parties developed a similar plugin for Bitbucket. I guess you’ll find it on pretty much every git platform today.

The idea is super simple. Just like with .gitignore files, you create a CODEOWNERS file in repository’s root directory (some platforms support additional locations) and use the a trivial format to define rightful owners for specific files or directories. It goes like this:

# Specific Code Owner[s] for a file
.gitlab-ci.yml @linux-dev1 @windows-dev1 @macos-dev1
# Specific Code Owner[s] for all cpp files in the linux directory
linux/*.cpp @linux-teamlead @linux-dev1 @linux-dev2
# Code Owners for a directory
windows/ @windows-dev1 @windows-dev2
# You can also specify a group as Code Owners for a file
windows/config.json @windows-group

As you can see, the format allows you to use wildcards and user groups to make code ownership management a simpler task as the company grows.

You might need to enable the plugin in your relevant CI/CD platform, for example, on GitHub:

And that is it! Now, every time someone touches any of the owned files, the rightful owner will be automatically added to the CR and has to approve the changes before these are merged into the protected branch.

Liked the idea? Make sure to share it with others! Want to hear more productivity tricks? Subscribe to D-Bits for more weekly hacks and tips.

Want to learn more about Monorepos and tools that help improve collaboration and productivity? check out this website!

--

--

Daniel Trugman
D-Bits
Editor for

A software specialist passionate about elegant and efficient technology. I Love learning and sharing my knowledge.