~/.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
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.
[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)" - 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...
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….
- 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.
what does this address that includeIf does not?
/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. # 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...
[includeIf "hasconfig:remote.*.url:https://*.github.com/**"]
path = /home/xani/src/gh/.gitconfig