A GitHub CLI extension to easily add co-authors to your latest commit.
gh-coauthor is a command-line tool that makes it easy to add GitHub users as co-authors to your most recent Git commit. It automatically fetches user information from GitHub API and formats the co-authored-by trailer according to Git standards.
gh extension install hsbt/gh-coauthor-
Clone this repository
git clone https://github.com/hsbt/gh-coauthor.git
-
Make the script executable
chmod +x gh-coauthor/gh-coauthor
-
Add the script to your PATH
Add a GitHub user as co-author to your most recent commit:
gh coauthor <username>Show the tool version:
gh coauthor versionDisplay help information:
gh coauthor --helpEnable shell completion:
source <(gh coauthor completion)# Add GitHub user 'pocke' as co-author to the latest commit
gh coauthor pocke
# Show version information
gh coauthor versionCOAUTHOR_DEBUG=1- Enable debug output
gh-coauthor automatically:
- Retrieves user details from the GitHub API
- Tries to find the user's email using various methods:
- From GitHub API (if public)
- From existing git history
- Falls back to GitHub's noreply email format
- Amends the most recent commit to add the co-author trailer
This project uses Bats (Bash Automated Testing System) for testing.
To run the tests:
-
Install Bats:
# On macOS with Homebrew brew install bats-core # On Ubuntu sudo apt-get install bats # Or from source git clone https://github.com/bats-core/bats-core.git cd bats-core ./install.sh /usr/local
-
Run the tests:
bats test/
The test suite includes tests for:
- Basic functionality verification
- Command options and flags
- Error handling
- Email fallback mechanisms
The original script for this tool was created by pocke and is available at https://gist.github.com/pocke/c54be87893aefa2be76abe1b2a4cdca5.
The command structure and organization were inspired by gh-signoff from Basecamp.