Gitas – A tool for Git account switching
github.com
github.com
~/.ssh/config
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/work_id_rsa
IdentitiesOnly yes
~/.git/config [user]
email = work@example.com
[remote "origin"]
url = github.com-work:Work/Widget.gitIn my main ~/.gitconfig I have:
[includeIf "gitdir:/home/user/projects/embedding-shapes/"]
path = /home/user/.gitconfig-embedding-shapes
Where basically `projects/` follow GitHub naming with $user/$repo, so I set the git identity based on all projects within that user, rather than repo-by-repo which would get cumbersome fast.Then you just make sure you're in the right directory :)
The next step of this problem space is: “when I’m working on project X, I often forget to change my GitHub user with Gitas” so now they need direnv or something to switch it for them. The original solution foresaw this - so is far more complete that Gitas already _and_ built into git itself.
But, LLMs, so here we are, slowly drowning in a growing ocean of software built by the unaware.
awash in bliss
[credential "https://github.com/org1"]
useHttpPath = true
helper =
helper = /path/to/auth.sh user1
[includeIf "hasconfig:remote.*.url:https//github.com/org1/**"]
path = user1.gitconfig
; set name / email in user1.gitconfig
where auth.sh is something that can produce the right token for the given user, e.g. #!/bin/bash
echo "username=$1"
echo "password=$(gh auth token --user $1)"Is there any good reasons not to separate what you work on into multiple GitHub accounts? Not to mention some people don't want all their projects attached to one profile, some people also develop in their free-time, and don't want to mix freetime/work projects under the same user account, for multiple reasons.
B if you ever be in a company using the half baked GitHub hosted enterprise….
- accounts (personal)
- orgs (companies, directories, teams, roles etc.)
- enterprises (sets of orgs)
Even with enterprise SSO, the initial connect to GH can (is typically) "you" (just as you have the same driver license to show at the front desk when registering to visit a secured firm or random hotel), then you elevate "you" into the org through SSO, and what policies apply to you via your org can be 'governed' at the enterprise.The idea behind this model is that no, you don't have to manage lots of those as you, you're just you, and each of those you aim to use has an elevation that entity controls instead of you controlling it.
This ultimately results in way less key material floating around, and you losing, leaking, or lousing up your own GH cred doesn't auto-give an attacker the SSO elevation.
• • •
Not incidentally, I have a slew of "accounts" given to me by companies that don't bother to make an org, they just invite individuals to repos or make individual accounts for their repo. I suppose it's cheaper in the short run. In the long run, these accounts are 90% still left active years to (no kidding) decade+ later. Seems a better idea to "don't do this." If you're a company, be an org.
---
* Expanded for more depth: https://docs.github.com/en/get-started/learning-about-github...
If they used their personal account for both, it could be unclear if they speak on behalf of our company or not.
- using alternative host is not supported when roaming between local and cloud, fix is to add another origin you don’t use but use GitHub.com url
- CC uses gh command, which still needs account switch, this can be solved by add the switch to CC hook.
You're presumably joking? If not, could you elaborate?
Tho I prefer to just use hardware key for ssh
That's only true when your machine is powered off. If an attacker manages to yank files from your disk while it is running, that ssh-key password is the difference between "they stole my ssh key" and "they stole worthless random data".
> use hardware key for ssh
That's the real solution. I don't understand why people still store ssh keys on disk when hardware keys are simple, easy, and significantly more secure.
At work, every place big enough to maybe care about this was so “enterprisey” and “cloudy” that I almost never use/used ssh anyway, even with tons of Linux systems all over the place. Pretty much only to talk to GitHub.
I lose stuff all the time. The idea of these things gives me anxiety. The first time I lost 15 minutes figuring out where I put my hardware key, before I could ssh in to do 20 seconds of running commands, I’d back out of the whole project and return to using a file on disk, guaranteed.
Files on disk are free, hardware keys cost money.
25 years as a backend-heavy programmer, sysadmin, and devops-sort (sometimes all at once, lol). I’ve still never even touched one of these devices, and have only rarely seen one.
Do you lose your keys? I just keep my main yubikey on my keychain. Never gets lost or else I'd be homeless. I keep a 2nd backup key in a secure place just in case, so I don't get locked out of my accounts if I get struck by lightning.
> hardware keys cost money
Barely. You can get u2f keys for $10-$20 which are usable with ssh. My yubikeys were $50 each (I have 2, one main key and one backup) which adds up to $100 but yubikeys are built like tanks, they'll last forever. I've had mine for the past 7 years and I have no reason to replace them. That's only $14/year so far for the pair of keys. Totally worth it for the knowledge that I could load every virus/trojan/keylogger known to man onto my computer and they still would be completely unable to steal my ssh+pgp keys.
It routinely takes me two to ten minutes to track them down, yeah. Every now and then, longer.
This is not true at all though. What about when you are logged into your computer.
source: https://erik.doernenburg.com/2017/12/using-multiple-github-a...
/some/where $ head .git/config
[user]
email = me@example.org
name = My 'nick' Name
Doesn't tie into your SSH key though, if you need that.Never access personal accounts from a work computer or work accounts from a personal computer under any circumstances.
This goes for laptops, desktops, and especially cellphones.
If an employer asks that you violate the above, ask for a dedicated device owned by your employer to access a work account. If they refuse, that's a big red flag. "Oh just use your phone to check your email/slack" - 1. don't assume everyone has a cellphone and 2. if you want folks doing work on a device, pay for it.
Managing multiple personal accounts on computer A or multiple work accounts on computer B is totally fine.
As an aside, company general counsels might be shocked at how often their employees log in to slack/email/etc. from their personal cellphone: suddenly any and all company and customer intellectual property has a way to leave the network. And it's not even a "pull" from the employee as the other employees just "push" them messages.
Obviously it should be everywhere, for all tools needed to do your job, but it's especially clear for tech where nearly all large companies will also exert control over the device.
# in ~/.gitconfig
[includeIf "gitdir:/home/user/projects/embedding-shapes/"]
path = /home/user/.gitconfig-embedding-shapes
# in ~/.gitconfig-embedding-shapes
[user]
name = embedding-shapes
email = embedding-shapes@proton.me
[core]
sshCommand = ssh -i /home/user/.ssh/id_embedding-shapes
That's one of my git "accounts", currently I have four in total, one being my "real identity", other are pseudo-anonymous users.[0] https://www.dvratil.cz/2015/12/git-trick-%23628-automaticall...
what does this address that includeIf does not?
[includeIf "hasconfig:remote.*.url:https://*.github.com/**"]
path = /home/xani/src/gh/.gitconfig [includeIf "hasconfig:remote.*.url:git@git.work:*/**"]
path = ~/.gitconfig.work
[includeIf "hasconfig:remote.*.url:https://git.work/**"]
path = ~/.gitconfig.work