Skip to main content

Command Palette

Search for a command to run...

Giving Co-author Credit in your GitHub Commits

or: How I Learned to Stop Worrying and Thank my Fellow Developers

Published
3 min read
Giving Co-author Credit in your GitHub Commits

We've all been there

You're flipping between tab upon tab upon tab of your browser, looking for an answer that seems to be arcane knowledge lost to time (or Google is taking your literal search as individual keywords and is giving you the opposite of what you need). So what happens then? For most people, your next step is to fire a message to another developer you know. A friend, acquaintance, co-worker, repository contributor; you're looking for answers and you're determined to fix this issue without compromising your creative integrity!

And then BAM! A ping from your device and suddenly you're trying these different solutions until you (hopefully) come across one that works. A sigh of relief comes from your debugging rubber duck as you finish strangling it in Developer Stress™, and you make your way to committing your changes. But as you're writing that commit message, it dawns on you: you should credit your savior for the work they put in to help you fix this! Or maybe you were pair programming with someone and you want to be a considerate developer who lets the world know who all worked on this commit. Either way, this will involve co-authoring your commit.

Please note that the following instructions are written with the prerequisite that all persons of interest are on GitHub.

Gathering Commit Emails

If you're using GitHub Desktop, you have it much easier! Scroll down to "Writing the Commit (GitHub Desktop)"

Start off by collecting the GitHub email addresses of the involved parties. If someone doesn't know off the top of their head, have them type git config --global user.email into their terminal; this will return the commit email address.

If you're unable to get this information from them directly, do not fear! There is a quick way to find the commit email address tied to their GitHub account through a commit from that user:

  • Go to the user's GitHub page; we'll use mine for this example

ghp.png

  • Go to a repository that the user has made commits in

ghr.png

  • Go to the commits for the repo, and click on a commit hash for a commit authored by the user who's commit email you're looking for

ghc.png

  • Once you're on the commit page, go to the address bar for your browser and add .patch to the end of the URL

ghcs.png

  • You'll find the commit email address here in the highlighted area

p.png

Writing the Commit (command line)

  • Start by writing your commit message as you normally would, except add two empty lines instead of a closing quotation mark
$ git commit -m "This is an example for my Hashnode article
>
>
  • On the next new line, add Co-authored-by: Example Name <name@exampleemail.com> with each author's information. Give each author their own line. Add a closing quotation mark after the last co-author and hit enter to commit your changes.
$ git commit -m "This is an example for my Hashnode article
>
>
Co-authored-by: Example <name@example.com>
Co-authored-by: Name <example@name.com>"

Writing the Commit (GitHub Desktop)

Thankfully, GitHub has this wonderful GIF that shows how to accomplish this in the GitHub Desktop client!

co-authors-demo-hq.gif

Source: GitHub Docs (https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors)

Results

co-author.png

Everyone gets their credit, visible for anyone who sees the commit on GitHub.

This is a feature I learned about in college, and it's one I've loved to share with every dev I've met since then!

Now it's your turn: go out and share the contribution love with your friends, acquaintances, co-workers, and repository contributors!

I

I don't know the CLI version, now I know 👍

1
M

Glad I could help teach you about it!

J

Great article Max! I had no idea this was a thing until you shared it with me, and I am so glad you wrote about it. Clearly written and easy to follow - looking forward to many more articles to come from you!!

1
M

Thank you so much for your kind words Erika! And also thank you for pushing me to try my hand at writing an article; I can't wait to see yours published!

1