Co-author commits with Git Mob

Because pairing is caring

Reading time: 3 min

Command line app:

VS Code extension:

Great teams build great software. Part of what makes a team great is their ability to work well with each other. In modern software development, collaboration is key.

We’re big fans of Extreme Programming at Findmypast. Many of our teams benefit from pair and mob programming. This is when two or more people share a computer to write code. In our experience, working like this helps us keep focus, increase code quality, reduce defects, and create a shared ownership.

Documenting code collaboration

When we work together, we should document that. It’s more than just giving credit to others, it’s also informing everyone about who was responsible for introducing changes to a codebase. Keeping a clear record of your work has lasting value - ever stumbled on an old commit only to be left with unanswered questions? In addition to explaining in your commits why a change was introduced, it also helps to document who implemented the change in case there needs to be a follow up.

We use GitHub, and GitHub has always been keen on collaboration. Their early slogan was “social coding”. Well, in January 2018, GitHub added support for commit co-authors and it’s great. Co-authors even get attribution in their contribution graph.

Adding co-authors to your commit can be done manually by appending a Co-authored-by trailer for every co-author when writing a commit message.

A commit message title A commit message body. Co-authored-by: Jane Doe <jdoe@example.com> Co-authored-by: Thomas Anderson <mr.anderson@example.com>

Why we built Git Mob

If you collaboratively code and rotate co-authors often, you may find the list of co-authors a chore to manage. It’s a cumbersome and error-prone process to manually record everyone who’s worked on a change, especially when it’s limited to a specific way that GitHub understands. For people who pair or mob program daily in their work environment, there has to be a better way where some of this would be automated.

There are existing CLI tools that help to keep track of co-authors in Git. We’ve used many of these over the past few years, but these tools were developed before the Co-authored-by trailer was supported by Git and GitHub. Instead the usual approach they took was to record one person as the author, and the other as the committer. This has some drawbacks, such as co-author support being limited to two people at any time, and commits losing their co-author metadata when history is rewritten (e.g. when using a command such as git-rebase). Some of these tools introduced workarounds to help with those problems, and though it helps, they’re still noticeable painpoints in the user experience.

We couldn’t find a tool that worked with the new commit message trailer, so we decided to build Git Mob during our 20% time that we get at Findmypast. Git Mob is a command-line tool to manage co-authors and to easily add the metadata to commit messages.

Getting started with Git Mob

Install Git Mob with npm.

npm install --global git-mob

Once installed, the commands git mob and git solo will be available.

Create a JSON list of co-authors in your user profile directory called ~/.git-coauthors .

{ "coauthors" : { "jd" : { "name" : "Jane Doe" , "email" : "jdoe@example.com" }, "ta" : { "name" : "Thomas Anderson" , "email" : "mr.anderson@example.com" } } }

Note that a person’s initials are used as the key in the “coauthors” object.

When using the git mob command, initials are given as arguments to identify co-authors.

$ git mob jd ta Richard Kotze <rkotze@example.com> Jane Doe <jdoe@example.com> Thomas Anderson <mr.anderson@example.com>

First output line is the author set on the user machine, and the remaining are the co-authors.

The git solo command clears co-authors when working on your own.

$ git solo Richard Kotze <rkotze@example.com>

Try Git Mob

Try Git Mob VS code extension and here is the Git Mob repository.

People who spend a lot of time writing code together will benefit most from this tool. Those who code solo most of their time won’t need this.

You can take a look at our Git Mob workflow on how to use it.

Please try Git Mob and let us know what you think. The project is still in its early stages and might have bugs or lack some features you’re looking for. We encourage you to submit feedback and contribute so we can make it better together.

The Co-authored-by metadata in commit messages is an agreed-upon trailer used by git-core contributors. GitHub uses this metadata to find the GitHub profiles of the co-authors, then visualises the data.

https://github.com/peterjwest/git-pair, https://github.com/hiremaga/git-mob, https://github.com/git-duet/git-duet