Where I’m at right now
What are some of the things going on in my life? Ugh, where to start.
Rambles that are fluffy, by fluffy
What are some of the things going on in my life? Ugh, where to start.
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.:
Thanks, Silas!
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 git@github.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.