Gimothy, a Git Identity Manager
Gimothy is an easy to use tool that helps you manage multiple git identities. At a mere ~100 lines of code, it’s easy to audit, too!
The Problem
As a software contractor, I frequently had to juggle multiple git accounts, usernames, and ssh keys. This quickly became a huge annoyance, so I chose to automate it. Of course, I was far from the first to encounter this problem and found many existing solutions, but none of those existing solutions seemed to meet all of my needs.
My ideal solution would be:
- Auditable
- I don’t want to blindly run code without knowing what it does, especially considering the sensitive nature of the ssh keys I held
- Cause Minimal Friction
- Repository setup should be automated
- It should not require any extra steps to preform basic git operations
- Support per-directory configuration
- This is an important feature as many companies choose to use GitHub, which makes host-based configuration useless
- It would also be nice to have the ability to set defaults in the parent directory that can be overridden by child directories
The Solution
The solution I conceived of is a small Python script that automates the task of configuring per-repository settings such as your username. It also sets the ssh key you have configured for that identity when running a git command.
The identities that Gimothy uses are configured in a single JSON file:
{
"identities": {
"<identity name>" : {
"privateKey" : "/full/path/to/private/key",
"user.name" : "your git username",
"user.email" : "your git email"
},
"<identity name>" : {
"privateKey" : "/full/path/to/private/key",
"user.name" : "your git username",
"user.email" : "your git email"
}
}
}
All one needs to do to configure a directory for a particular identity is navigate to that directory and run:
$gim --gim-init <identity name>
This will configure your email, username and create a .gim file in the current directory that tells gim which identity to use (you may wish to add this .gim file to your .gitignore).
From this point, Gimothy is almost entirely seamless. Just replace “git
” with “gim
” when preforming git operations and Gimothy will take care of the rest:
$gim <any standard git command(s)>
Interested in giving Gimothy a try? Have a look at the GitHub repo for installation instructions.