Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

git-mob

rkotze1.3kMIT4.0.1

CLI tool for adding co-authors to commits.

cli, cli-app, git-pair, git-duet, git, github, co-author, pairing, pair programming, mob programming, extreme programming, xp, social coding

readme

Git Mob - Co-author commits

npm downloads npm version

A command-line tool for social coding

Add co-authors to commits when you collaborate on code. Use when pairing with a buddy or mobbing with your team.

Buy Me A Coffee

✨ Git Mob VS Code extension

gif showing example usage of git-mob

Install

git-mob is a CLI tool, so you'll need to install the package globally.

npm i -g git-mob

MacOS use Homebrew

brew install git-mob

By default git-mob will use the global config .gitmessage template to append co-authors.

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 "jane@example.com"

To keep track of co-authors git-mob uses a JSON file called .git-coauthors, and will try to find it in the following directories:

  1. If GITMOB_COAUTHORS_PATH environment variable is set this will override any other settings.
  2. If the current Git repository has a .git-coauthors file in the root directory.
  3. The default is the users home directory at ~/.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. Also see add co-author command.

$ cat <<-EOF > ~/.git-coauthors
{
  "coauthors": {
    "ad": {
      "name": "Amy Doe",
      "email": "amy@findmypast.com"
    },
    "bd": {
      "name": "Bob Doe",
      "email": "bob@findmypast.com"
    }
  }
}
EOF

You're ready to create your mob. Tell git-mob you're pairing with Amy by using her initials. git mob ad

$ git mob ad
Jane Doe <jane@example.com>
Amy Doe <amy@example.com>

Commit like you normally would. You should see Co-authored-by: Amy Doe <amy@example.com> 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 <jane@example.com>
Amy Doe <amy@example.com>
Bob Doe <bob@example.com>

Once you're done mobbing, switch back to developing solo.*

$ git solo
Jane Doe <jane@example.com>

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

Add co-author from GitHub

Provide the GitHub username to generate their co-author details. The anonymous GitHub email is used. You need to enable it see config.

$ git mob rkotze
Jane Doe <jane@example.com>
Richard Kotze <10422117+rkotze@users.noreply.github.com>

Custom setup

Using git commit -m setup

How to append co-authors to the message when using message flag - git commit -m "commit message"?

  1. Add prepare-commit-msg hook file in .git/hooks dir. See hook-examples
  2. 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.

Using pre-commit to install

You can install the git hook using [pre-commit](https://pre-commit.com/). Add the following to your pre-commit-config.yaml

repos:
  - repo: https://github.com/rkotze/git-mob
    rev: { tag-version }
    hooks:
      - id: add-coauthors
        stages: ['prepare-commit-msg']

And install with: pre-commit install --hook-type prepare-commit-msg.

Removing the above snippet and running git commit will uninstall the pre-commit hook

Revert back to default setup

  1. Remove relevant scripts prepare-commit-msg file

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

Enable GitHub author fetch

To fetch authors from GitHub you need to enable it using the config.

type: Boolean, scope: global, version: 2.3.3

git config --global git-mob-config.github-fetch 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 jane@example.com
ad Amy Doe amy@example.com
bd Bob Doe bob@example.com

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 jane@example.com
ad Amy Doe amy@example.com

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" barry@butterworth.org

Suggest co-authors

Suggest co-authors from contributors in local Git repository and add to .git-coauthors file.

Optional author filter by name or email.

$ git suggest-coauthors [author name | author email]

Path to .git-coauthors

Print out path to .git-coauthors file.

git mob -p

Open co-author file: git mob -p | xargs code

Help

Find out more.

git mob -h

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

More info

See git-mob discussions

Read our blog post to find out why git-mob exists: Co-author commits with Git Mob

* If you have git-duet installed, you'll need to uninstall it since it conflicts with the git-solo command.

changelog

Change Log

Follows Semantic Versioning.

git-mob-core 0.10.1

Fixed

  • If an email has partially the same email as another co-author they will get included. This addresses this issue. Issue 213

git-mob 4.0.0

Added

  • Update to suggest-coauthors will show a select interactive list using inquirer/checkbox. Select one or more authors to save. Reducing the number of steps to add new co-authors.
  • Finished migration to TypeScript for the main files in git-mob and git-mob-core packages. Issue 83

Breaking

  • Removed the following commands because I think they are low value to maintain. See readme on how to edit/delete co-authors.
    • git delete-coauthor
    • git edit-coauthor

git-mob-core 0.10.0

Added

  • Expose a public function to format Git message co-author trailers in one place. For consumers like Git Mob VS Code extension.

git-mob-core 0.9.3

Added

  • Migrate git template git-messages function to TypeScript.

Fixes

  • When no path set for the commit template, default to the global template. Don't use a relative path.

git-mob-core 0.9.2

Fixes

  • Global path to .git-coauthors can be overwritten by env var GITMOB_COAUTHORS_PATH.

git-mob-core 0.9.1

Fixes

  • When creating a new .git-coauthors using the createCoAuthorsFile it is created only globally by providing internally the global path.

git-mob-core 0.9.0

Added

  • Specify authors to save when creating the coAuthor file.
  • Clean up unused features in author file: coAuthor, author format functions and no need for the write method.
  • Remove unused old command API
  • Convert GitAuthors function to TypeScript and define new internal type CoAuthorSchema.
  • Breaking: getSelectedCoAuthors now returns a promise with type Author[].
  • Breaking: getPrimaryAuthor now returns a promise with type Author.
  • Breaking: setPrimaryAuthor now returns a promise void.
  • New: searchGitHubAuthors search by name and this will return Author[].

git-mob 3.2.0

Added

  • Integrate breaking changes in core API: getPrimaryAuthor, getSelectedCoAuthors, setPrimaryAuthor.
  • New flag -p path will print out path to .git-coauthors file.

git-mob 3.1.1

Added

-- git suggest-coauthors [author name or author email] can filter by author name or email. Addresses issue 90

Refactored

  • Remove legacy git-message API and replace it with git-mob-core git-message API
  • Remove legacy git-add-coauthor API and replace it with git-mob-core saveNewCoAuthors
  • Remove legacy git-suggest-coauthor API and replace it with git-mob-core repoAuthorList
  • Migrated git-suggest-coauthors to TypeScript
  • git mob-print -i uses git mob core to print out initials of selected co-authors
  • Post install script to create global coauthor file uses createCoAuthorsFile from git mob core
  • Migrated mob print file to TypeScript
  • Removed legacy git mob commands no longer used.
  • Removed legacy git commands no longer used.

git-mob-core 0.8.2

Added

  • Added function to create a global coauthor file createCoAuthorsFile.

git-mob-core 0.8.0

Added

  • Added repoAuthorList which will list all contributors from a repo
  • Added filter to repoAuthorList which uses --author flag from git shortlog.

Refactored

  • Add new co-author module migrated to TypeScript and tested
  • Change to async topLevelDirectory, insideWorkTree - may not be needed in future versions
  • resolve-git-message-path migrated to TypeScript
  • Changed to async resolveGitMessagePath, setCommitTemplate

git-mob 3.0.0

Added

  • Now uses ESM modules and requires Node 16+ (Most parts work with Node 14)
  • CI run tests in 3 Node environments 14, 16, 18
  • Updated dependencies and dev dependencies to patch security issues
  • Updated tests to support ESM

git-mob-core 0.7.0

  • Requires Node 16+
  • Module systems support ESM and CJS

git-mob-core 0.6.0

Added

gitMobConfig = {
  localTemplate(): <Promise<boolean>>,
  fetchFromGitHub(): <Promise<boolean>>,
};

gitConfig = {
  getLocalCommitTemplate(): <Promise<string>>,
  getGlobalCommitTemplate(): <Promise<string>>,
};

gitRevParse = {
  insideWorkTree(): string,
  topLevelDirectory(): boolean,
};

git-mob 2.5.0

Added

  • Integrated git-mob-core for main git mob features
  • Reduced the calls to git CLI to speed up command execution for git mob
  • Convert src git-mob and spec files from JS to TS

git-mob-core 0.5.0 10-06-2023

Added

  • Added config manager feature to set the child process cwd when needed see issue 109. New functions getConfig and updateConfig.

git-mob 2.4.0 21-05-2023

Added

  • Integrated git-mob-core solo function
  • Override the global .git-coauthors file with one specified in root folder of a Git repository. Thanks to @tlabeeuw

git-mob-core 0.4.0 21-05-2023

Added

  • updateGitTemplate will keep global template up to date if local one is used for current repository.
  • pathToCoAuthors will return the path to .git-coauthors file.