New Project: git-multi-email
git-multi-email solves the issue of using multiple email addresses in Git on a single machine. It’s a global Git hook for changing your email address as necessary in the Git configuration local to the current repository as an alternative to changing your email address manually per repository.
For an example, consider the following directory structure on your machine:
And the following configuration in your global
.gitconfig (found at
~/.gitconfig on your machine):
Normally, when a commit is made,
firstname.lastname@example.org is used as the email address.
Now, with git-multi-email, when a commit is made in a local repository anywhere within a folder named
email@example.com will be used as the email alias and set locally for future use in that repository. Similarly, when a commit is made in a local repository anywhere within a folder named
firstname.lastname@example.org will be used as the email alias. Otherwise, any commit outside of these directories will use the default
email@example.com email address.
Here’s a full demo using the example configuration:
If you were to remove a line from the
[emails] section in your
~/.gitconfig file, then any Git repository where the email address changed within that directory will not automatically change back to the default email address (meaning
git config user.email will still be the overridden email address).
If you do come across this issue, a quick fix is to set the
user.email back to your default email address for that repository (ex:
git config user.email "firstname.lastname@example.org").
There are no tests yet, but I’ve considered a solution that uses Docker for tests so that the tests are fully independent of existing Git configurations on a local machine.
That’s it! See the project on on GitHub for the installation guide.
Issues and pull requests are welcome!