Skip to content

noahbass/git-multi-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-multi-email

MIT License GitHub tag Build Status

Automatically changes git config user.email based on path

Working on projects for multiple organizations? This git hook changes your email address as necessary in the git config local to the current repository before commit.

asciicast

Getting started

Clone with git clone https://github.com/noahbass/git-multi-email.git. Then cd git-multi-email.

Ensure you have a core hooks directory (ex: ~/.git-config/hooks/). If not, use mkdir -p ~/.git-config/hooks/ to create it and use git config --global core.hooksPath ~/.git-config/hooks/ to configure that directory as your hooks path.

git config --global core.hooksPath ~/.git-config/hooks/

Then, use these commands to copy the hook to the global hooks folder:

  • cp ./post-commit ~/.git-config/hooks/post-commit
  • chmod a+x ~/.git-config/hooks/post-commit
  • mkdir ~/.git-config/hooks/vendor/
  • cp ./vendor/ini-parser.sh ~/.git-config/hooks/vendor/ini-parser.sh

Next, configure your ~/.gitconfig file...

Configuration

Update your ~/.gitconfig file to include a new section called [emails]. Example configuration file:

...
[user]
	name = Noah Bass
	email = [email protected]
[emails]
	astronomerio = [email protected]
	acmatuc = [email protected]

So now, any commit made in a repo within a folder named astronomerio will use [email protected] as the email address. Similarly, any commit made in a repo within a folder named acmatuc will use [email protected] as the email address. Otherwise, commits will use the default [email protected] as the email address.

(Remember that the .gitconfig file follows the INI format)

Notes

  • Requires Git v2.9.0 or later
  • Not tested on Windows

Hacking on git-multi-email

TODO

Tests

Run tests with Docker! Use docker build -t git-multi-email-test . --no-cache --rm to build the image, then docker run --rm git-multi-email-test to run the tests.

Or, you can choose to run the tests without Docker by using sh ./test/setup.sh, then sh ./test/test.sh.

Note: tests running on Travis CI use Docker.

License

MIT License