Skip to content

Instantly share code, notes, and snippets.

@kyle-west
Created November 27, 2019 16:13
Show Gist options
  • Select an option

  • Save kyle-west/480191af12509e6acfae276a067c07dd to your computer and use it in GitHub Desktop.

Select an option

Save kyle-west/480191af12509e6acfae276a067c07dd to your computer and use it in GitHub Desktop.
Append a commit message with a "Co-authored-by" message with just a GitHub username
#!/bin/bash
###########################################################################################
# co-authored : append a Co-authored-by message to your commit history with just a username
# co-authored <github-username> [<github-username>...]
###########################################################################################
for coAuthorUsername in $@; do
msg=$(git log --format=%B -n1)
coAuth="Co-authored-by: $(json <(curl -s "https://api.github.com/users/${coAuthorUsername}") $.name) <${coAuthorUsername}@users.noreply.github.com>"
git commit --no-verify --amend -m "$msg" -m "$coAuth" >/dev/null
done
git log -n1
@kyle-west
Copy link
Author

Install

Best installed via bashful CLI.

bashful gist install https://gist.github.com/kyle-west/480191af12509e6acfae276a067c07dd

Usage

co-authored takes a list of GitHub usernames as strings. It adds their credit info to your latest commit message.

Example

After writing up your commit message, run the following command to add (for example) @kyle-west as a commit co-author

co-authored kyle-west

It will change the commit message from this:

Author: Your Name <[email protected]>
Date:   Tue Nov 26 14:07:49 2019 -0700

    Here is a detailed message of what I did.

To this:

Author: Your Name <[email protected]>
Date:   Tue Nov 26 14:07:49 2019 -0700

    Here is a detailed message of what I did.

    Co-authored-by: Kyle West <[email protected]>

And everyone will receive credit where credit is due.

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