This works great, thanks. Note: if you forget the trailing slash of the gitdir path, you get a standard permission denied error with AFAICT no options to debug since ssh connects fine, it’s just the filter that doesn’t work. So I thought I’d leave this here for future reference.
A problem arises with this trick when your repo uses submodules that can only be accessed by a specific account. The problem is that you’ll need to change the urls in your .gitmodules file as well, which you then can’t commit. If anyone happens to know a way around that, I’d love to know :)
One person or legal entity may maintain no more than one free Account (if you choose to control a machine account as well, that’s fine, but it can only be used for running a machine).
However, I wonder what kind of motivation people have for leading a double life that don’t require stronger anonymity measures than just separate accounts.
If you do it sometimes, then pushing over HTTPS with user/password auth doesn’t seem like a serious inconvenience. It also has a better chance to work through corporate filters.
I use this trick with my local GoCD hosting, since it doesn’t allow you to configure which ssh key you want to use for a version control checkout. Though it looks like I might swap to wbolster’s trick.
Related: remember that your commits are tied to an email address. If you want to associate them with your account long-term (eg, your open source work), be sure you use an email address you control long-term (eg, not a work address).
the same goal can usually be achieved with this one time setup (instead of per repo):
multiple @github accounts without messing with hostnames in ssh configs & standard git: urls for cloning:
https://twitter.com/wbolster/status/1127265684319293440
This works great, thanks. Note: if you forget the trailing slash of the gitdir path, you get a standard permission denied error with AFAICT no options to debug since ssh connects fine, it’s just the filter that doesn’t work. So I thought I’d leave this here for future reference.
A problem arises with this trick when your repo uses submodules that can only be accessed by a specific account. The problem is that you’ll need to change the urls in your .gitmodules file as well, which you then can’t commit. If anyone happens to know a way around that, I’d love to know :)
see my other comment or this tweet
https://twitter.com/wbolster/status/1127265684319293440
Well, the trick is not a trick at all - this is pretty standard
OpenSSH
config. Obviously, not limited toGit
orGitHub
, et al.In terms of actual
Git
, I like @wbolster’s solution much more, especially if one copy-pastes URLs a lot - no need to remember to modify them.Please note that this may technically violate GitHub’s terms of service, see section B.3. Account Requirements:
Not necessarily - the clue is in the word free. One can have a free personal account and a business work account, and all is well :^)
Thanks for pointing this out. I’ve adjusted my wording to make clear you’re not always going to be in violation.
Separate local users can do the job, too. Each gets its own
~/.gitconfig
and~/.ssh
.That’s a neat trick.
However, I wonder what kind of motivation people have for leading a double life that don’t require stronger anonymity measures than just separate accounts.
I’d sometimes do personal stuff on my work laptop at home at my last job. This would have been great to have then.
If you do it sometimes, then pushing over HTTPS with user/password auth doesn’t seem like a serious inconvenience. It also has a better chance to work through corporate filters.
If you have a github account for work, then you likely can push to that through ssh already.
When I want to do that I usually just SSH from my work laptop to my personal one.
That’s nice. I usually work with a combination of direnv and setting GIT_SSH properly.
I use this trick with my local GoCD hosting, since it doesn’t allow you to configure which ssh key you want to use for a version control checkout. Though it looks like I might swap to wbolster’s trick.
nice post =)
Related: remember that your commits are tied to an email address. If you want to associate them with your account long-term (eg, your open source work), be sure you use an email address you control long-term (eg, not a work address).
I used this trick so you don’t have to change remote path or anything. Create a file
kgit
in~/bin
Whenever I need to switch to personal account:
This tell git when cloning/pushing via SSH it will use the right personal ssh key.
You can also create a shell function and put it into your rc file:
Now simply run
kgit
in your shell.