git-mob
git-mob copied to clipboard
Co-author commits tool. A cross-platform command-line tool for social coding. Includes co-authors in commits when pair/mob programming.
Git Mob

A command-line tool for social coding
Includes co-authors in commits when you collaborate on code. Use when pairing with a buddy or mobbing with your team.
📣 Findmypast engineering team have handed me ownership of Git-Mob. Shout out to them because they have a great engineering culture who enabled me to build Git Mob.
Read our blog post to find out why git-mob exists: Co-author commits with Git Mob

- Install
- Using
git commit -msetup - Revert back to default setup
- Using
- Workflow / Usage
- Git Mob config
- More commands
- List all co-authors
- Overwrite the main author
- Add co-author
- Delete co-author
- Edit co-author
- Suggest co-authors base on current repo
- Add initials of current mob to your prompt
- Bash
- Fish
Install
git-mob is a CLI tool, so you'll need to install the package globally.
npm i -g git-mob
By default git-mob will use the global config .gitmessage template to append co-authors.
Using git commit -m setup
How to append co-authors to the message when using message flag - git commit -m "commit message"?
- Add
prepare-commit-msghook file in.git/hooksdir. See hook-examples - The hook will need to be executable
chmod +x prepare-commit-msg
prepare-commit-msg will need a script to read the co-authors, which can be done via git mob-print. See hook-examples folder for working scripts.
The command git mob-print will output to stdout the formatted co-authors.
Note: > v1.1.0 git mob --installTemplate and git mob --uninstallTemplate has been removed.
Revert back to default setup
- Remove relevant scripts
prepare-commit-msgfile
Workflow / Usage
With git-mob, the primary author will always be the primary user of the computer. Set your author info in git if you haven't done so before.
$ git config --global user.name "Jane Doe"
$ git config --global user.email "[email protected]"
To keep track of potential co-authors, git-mob uses a JSON file called ~/.git-coauthors.
Here's a template of its structure.
{
"coauthors": {
"<initials>": {
"name": "<name>",
"email": "<email>"
}
}
}
Start by adding a few co-authors that you work with.
$ cat <<-EOF > ~/.git-coauthors
{
"coauthors": {
"ad": {
"name": "Amy Doe",
"email": "[email protected]"
},
"bd": {
"name": "Bob Doe",
"email": "[email protected]"
}
}
}
EOF
You're ready to create your mob. Tell git-mob you're pairing with Amy by using her initials. git mob ad
Selected co-authors are stored globally meaning when switching between projects your co-authors stay the same*.
*Note: If you've set a local commit template in your config then that template will be updated. However, not when you switch projects and you will see a warning. You can run git mob to update the commit template. Read more here
$ git mob ad
Jane Doe <[email protected]>
Amy Doe <[email protected]>
Commit like you normally would.
You should see Co-authored-by: Amy Doe <[email protected]> appear at the end of the commit message.
Let's add Bob to the group to create a three-person mob.
$ git mob ad bd
Jane Doe <[email protected]>
Amy Doe <[email protected]>
Bob Doe <[email protected]>
Once you're done mobbing, switch back to developing solo.*
$ git solo
Jane Doe <[email protected]>
Git Mob config
Git Mob config is a section in the Git config.
Use local commit template
If you are using a local commit template and want to remove the warning message then set this option to true. Only reads from the local git config.
type: Boolean, scope: local, version: 2.2.0
git config --local git-mob-config.use-local-template true
More commands
List all co-authors
Check which co-authors you have available in your .git-coauthors file.
$ git mob --list
jd Jane Doe [email protected]
ad Amy Doe [email protected]
bd Bob Doe [email protected]
Overwrite the main author
Overwrite the current author which could be useful for pairing on different machines
If the current author is: Bob Doe
$ git mob -o jd ad
jd Jane Doe [email protected]
ad Amy Doe [email protected]
Now the author has changed to Jane Doe.
Add co-author
Add a new co-author to your .git-coauthors file.
$ git add-coauthor bb "Barry Butterworth" [email protected]
Delete co-author
Delete a co-author from your .git-coauthors file.
$ git delete-coauthor bb
Edit co-author
Edit a co-author's details in your .git-coauthors file.
$ git edit-coauthor bb --name="Barry Butterworth" --email="[email protected]"
$ git edit-coauthor bb --name="Barry Butterworth"
$ git edit-coauthor bb --email="[email protected]"
Suggest co-authors base on current repo
Suggest some co-authors to add based on existing committers to your current repo
$ git suggest-coauthors
Add initials of current mob to your prompt
Bash
Add the initials to PS1, in ~/.bashrc
function git_initials {
local initials=$(git mob-print --initials)
if [[ -n "${initials}" ]]; then
echo " [${initials}]"
fi
}
export PS1="\$(pwd)\$(git_initials) -> "
Fish
Add the following functions to .config/fish/config.fish
function git_initials --description 'Print the initials for who I am currently pairing with'
set -lx initials (git mob-print --initials)
if test -n "$initials"
printf ' [%s]' $initials
end
end
function fish_prompt
printf "%s%s ->" (pwd) (git_initials)
end
* If you have git-duet installed, you'll need to uninstall it since it conflicts with the git-solo command.
Find out more with git mob -h