A better way to handle multi-account GitHub

Comments

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:

~/.ssh/config
Host  github-work
  Hostname github.com
  IdentityFile ~/.ssh/id_work
Host github-personal
  Hostname github.com
  IdentityFile ~/.ssh/id_personal

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:

~/.gitconfig
[includeIf "gitdir:~/wfh"]
path = ~/.gitconfig-work

then .gitconfig-work includes your work-specific configuration, e.g.:

~/.gitconfig-work
[user]
name = Boring Legal Name
email = work-email@example.com

Thanks, Silas!

Updates

Comments

Oops, I guess I haven’t been posting here as often as I’d like. I guess I’ve mostly been using Discord to keep in touch with folks.

I’m fairly busy at the day job. I’ve already rolled out a few important features for our websites and soon I’ll be ramping up on another project. So far everyone there has been super great and I’m glad I lucked out with this job, even without the societal/financial catastrope that happened shortly after I started.

Isolation hasn’t been great for me. I’ve been having a pretty bad fibro flareup lately, and I still haven’t quite shaken whatever this dang thing I have is. It’s not gotten severe enough to require medical attention but at the same time I’d love to not be missing occasional workdays when I’m feeling especially lousy. It might also just be part of the fibro flare, too. Fortunately the new job has unlimited sick days, because dang I’ve been taking a lot of them this past month.

I’ve had to switch back to decaf because it turns out having even half-caf espresso every day has gotten me sensitized to caffeine again, and I was starting to have panic attacks again. Phooey. I still love my Flair though. I’ve also had a couple of people ask me about selling my custom tampers so I should see about, like, doing that.