cc by-sa flurdy

Git Pair Commit Attribution

Attributing both members of a pair in the commit history of git based project.

Started: January 2016. Last updated: 27th January 2016.

Pair programming, which is a common practice in modern software teams, means two people are responsible for the work developed. But all the commits in Git's history are normally only in one persons details.

By attributing both pair members praise (and blame ;p) and most likely future questions can be directed to both, instead of just the owner of the machine it was developed on.

As Git does not support this out of the box, there are several work-arounds:

  • Alternate commits

    Alternate commits between the members randomly or in alternate order.

  • Separate author and commiter

    Use the separate author and committer git settings to split attributions. E.g.:

    GIT_AUTHOR_NAME="John Smith"
    GIT_AUTHOR_EMAIL="[email protected]"
    GIT_COMMITTER_NAME="Sue Jones"
    GIT_COMMITTER_EMAIL="[email protected]"

There are many alternative tools to accomplish this:

Git_scripts by Pivotal

This howto will show how to use github.com/pivotal/git_scripts by Pivotal, which do support the alternate commit authors solution, but more importantly it also supports a 3rd option: Merge.

Merge the committers

Merging the both pair members as one committer means combining both names as one, and a still valid email address that represents both members. E.g.

GIT_COMMITTER_NAME="Sue Jones and John Smith"
GIT_COMMITTER_EMAIL="[email protected]"

As you can see the merge option combines the names and appends the email alias with a + separating. This makes it a valid email address which is still Sue's as all mail servers will ignore what is between + and @.

Install Git_scripts

The scripts are available as a Ruby Gem:

gem install pivotal_git_scripts

You may need to sudo this command if root privileges is required.

Configuration

Create a ~/.pairs file.

vi ~/.pairs # .pairs - configuration for 'git pair'
pairs:
# <initials>: <Firstname> <Lastname>[; <email-id>]
js: John Smith; john.smith
sj: Sue Jones; sue.jones
aw: Alun Wilson; alun.wilson
email:
prefix: devs
domain: example.com
# no_solo_prefix: true
global: false

If prefix is not empty it will prefix emails with its value. E.g. in the above devs will result in:

GIT_COMMITTER_EMAIL="[email protected]"

So that all emails will end up in [email protected], which may be an alias for the whole dev team. A blank prefix may be preferable so that the email addresses generated are sent to at least one of the pair. (The pair order is alphabetic)

If global is true, this will set these values globally across all git repositories on your machine. Using the --global option will do the same.

Alternatively create another script that loops around an environment variable of projects or root folder to pair on.

Start pairing

If John and Alun are pairing on a project then use their initials with Git pair:

cd /path/to/project;
git pair js au

The pair has now been set up.

git config user.name GIT_COMMITTER_NAME="Alun Wilson and John Smith" git config user.email GIT_COMMITTER_EMAIL="[email protected]"

Commit code

All commits in this project will now be attributed to Alun and John.

echo blaaaaah > aha.txt;
git add aha.txt;
git commit -m "paired";
git show --name-status
commit 2e2dasdsadasdasdasdasdas
Author: Alun Wilson and John Smith <[email protected]>
Date: Wed Feb 29 20:36:33 2013 +0000
....

Finish pairing

At the end reset back to just yourself (John Smith) with:

git pair -u; git config user.email GIT_COMMITTER_EMAIL="[email protected]"

You may want to create a git alias like git solo to accomplish the same thing.

Alternate commits with git_scripts

If you want to have commit history to be real people and only one person per commit, then you can instead use:

git pair-commit

This does not merge the details but chooses a pair member randomly to be the committer.

Avatar

Optionally you may want to add the merged email addresses to Gravatar so that SourceTree, GitHub and other GUI git tools will show a relevant avatar.

You might create morphed or merged avatars from both members photos.

Feedback

Please fork and send a pull request for to correct any typos, or useful additions.

Buy a t-shirt if you found this guide useful. Hire Ivar for short term advice or long term consultancy.

Otherwise contact flurdy. Especially for things factually incorrect. Apologies for procrastinated replies.