Over the past couple weeks my pain has been flaring up again, driven especially by work stress. A few days ago I hit a breaking point and realized that this is something I need to actually take short-term disability leave for.
Fortunately, Moz has an extremely generous disability leave program, and management would much rather someone take it if necessary. So, for now I’m off from work until August, and we’ll see where things go from there.
I mentioned my crappy approach to using multiple GitHub accounts on a Slack I’m on, and someone else pointed out there’s a much easier approach: Instead of using wrapper scripts to set up different environments, you can fake it using .ssh/config and .gitconfig rules.
First, set up key rules with .ssh/config:
Next, set your origin based on whether the workspace is work or personal; for example, git clone git@github-work:work-org/project.git (and of course you can git remote set-url origin for existing workspaces).
Finally, to handle the different author name and email, git 2.15 and later support conditional includes. If you keep all of your work projects in a separate directory, you can put this into your .gitconfig:
then .gitconfig-work includes your work-specific configuration, e.g.:
Let’s say you’re stuck working from home due to an ongoing apocalypse. Let’s say that you use separate GitHub accounts for personal projects vs. work (for one of any number of reasons), and that when you’re working from home you’re using a personal computer. Let’s say that for Reasons it’s not feasible for you to juggle multiple user accounts on said computer, and you need to be able to access both of your GitHub accounts without a lot of hassle.
The main problem is that GitHub ties your ssh key to your account (out of necessity), but all connections to GitHub are via the master email@example.com account, so there’s no easy way to differentiate which key to use at runtime.
So, here’s how I managed to set things up so that I could select a GitHub account on a per-shell basis.