Skip to content

Instantly share code, notes, and snippets.

@lisawolderiksen
Created October 29, 2019 21:06
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lisawolderiksen/f9747a3ae1e58e9daa7d176ab98f1bad to your computer and use it in GitHub Desktop.
Save lisawolderiksen/f9747a3ae1e58e9daa7d176ab98f1bad to your computer and use it in GitHub Desktop.
Add co-authors to Git commits

Adding co-authors to Git commits

How do you share credit for a new or altered piece of code when one person commits the change in a pair programming or mob programming session? And when you have questions about a particular change, how can you see in Git who has been working on that change, besides the committer? You add co-autors to your commits. This gist contains information on how to do that, so that the Git commit message contains a list of co-authors, and all co-autors for a commit are automatically listed in GitHubs web UI.

GitHub has some info on specifying co-authors here. This is good info, pretty straightforward. The gist of it (pun intended) is to include at least one blank line and then a line for each co-author like so Co-authored-by: name <name@example.com> at the very end of your commit message.

GitHub's recipe tells you how to find the right e-mail address to use (the GitHub-provided no-reply address if appropriate), as well as how to create co-authored commits using GitHub Desktop, how to create co-authored commits when using the web editor on GitHub, and how to create co-authored commits on the command line. The latter is most relevant for our team.

The recipe created by GitHub is a good one. Use it! :) ...But there is one thing which might be a source of confusion - the number of empty lines required between the end of the commit description and the co-author section. The GitHub recipe includes the following tip:

If you're using a text editor on the command line to type your commit message, ensure there are two lines between the end of your commit description and the Co-authored-by: commit trailer.

The thing is that when I do this, no matter how many blank lines I put between the co-author info and the previous part of the commit message in the editor, the resulting actual commit message contains only one empty line there. But it's OK, the actual requirement seems to be at least one empty line (i.e. two "newline" characters) between the description and the co-author section. So there's no need to worry and do git commit --amend to fix the commit message like I did, the end result displayed in the GitHub UI is the same as long as there is one empty line before the co-author section. :)

To avoid having to remember how to do this every time I make a commit during a pair/mob programming session, I added this info to my commit message template, which is described here. So when I do git commit and my editor opens, I have all the info I need to write a good commit message - including how to credit co-authors. :)

@NikhilMath
Copy link

What are the preamters of when you should do a coauthor?
Cause techincally, all my information I know is through a coworker, cause were a team. Should every commit be a coauthor? I know it techincally doesnt matter, but for community sake, what should I do?

@lisawolderiksen
Copy link
Author

What are the preamters of when you should do a coauthor? Cause techincally, all my information I know is through a coworker, cause were a team. Should every commit be a coauthor? I know it techincally doesnt matter, but for community sake, what should I do?

Every team is different, and opinions on this probably vary, but I like to use Co-authored-by for every single commit I make when I'm controlling the keyboard in a pair programming or mob programming session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment