top | item 47099044

(no title)

Kwpolska | 9 days ago

Solving the problem of having a personal and a work GitHub account is really trivial without any extra tools. All you need is a dedicated SSH key for that GitHub account. (And why would you have a password for a ssh key on your personal machine?)

~/.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.git

discuss

order

embedding-shape|9 days ago

Which works for a while, until you have a bunch of projects under various identities.

In 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 :)

beaker52|9 days ago

This. I’ve seen so many tools solving problems that already have solutions lately because LLMs allow people to run off and “fix” the problem their way before they can a chance to discover existing, more appropriate solutions.

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.

accoil|9 days ago

I use that approach. I also make sure to not set the [user] section in my main config (and only in the included files). That way if I'm operating outside of one of my user directories git commit fails due to having no user details.

arccy|9 days ago

If you don't want to bother with directories or want to use https instead of ssh, you can do remote url based dispatch in your gitconfig:

    [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)"

xn|9 days ago

Are there any good reasons to use multiple GitHub user accounts? GitHub organization membership and permissions are well designed in my experience, negating the need for multiple user accounts.

StarlaAtNight|9 days ago

Consultants or professional services folks will be working in their company’s GitHub account and several clients. Requires managing lots of git/GitHub accounts

embedding-shape|9 days ago

> Are there any good reasons to use multiple GitHub user accounts?

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.

Hamuko|9 days ago

I use a pseudonym during my free time, so yes. Also my employer is requiring us to use company-specific GitHub accounts, so the decision is out of my hands anyway.

magicalhippo|9 days ago

We went with that primarily due to requiring SSO and because we might want employees to interact with other projects with the company hat on.

If they used their personal account for both, it could be unclear if they speak on behalf of our company or not.

jimmydoe|9 days ago

A why not

B if you ever be in a company using the half baked GitHub hosted enterprise….

hrpnk|9 days ago

The host shenanigans are simpler addressed with `git config core.sshCommand` which overrides the default key and selects the desired one on a per repository level.

source: https://erik.doernenburg.com/2017/12/using-multiple-github-a...

CamJN|9 days ago

Doesn’t work for cloning, obviously. The way I handle it is I have ssh look at the hostname and path passed by git and decide which identity to use. This is very easy in openssh 10.0+ using the command matching syntax, and more difficult to varying degrees on earlier versions of openssh, depending on your OS.

OrderlyTiamat|9 days ago

> (And why would you have a password for a ssh key on your personal machine?)

You're presumably joking? If not, could you elaborate?

PunchyHamster|9 days ago

well if you have encrypted storage and already need password to get to it, secondary password is of little value

Tho I prefer to just use hardware key for ssh

jimmydoe|9 days ago

For Claude Code users:

- 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.

adithyassekhar|9 days ago

Is this that dropbox moment again? Anyway on Windows I keep a separate work and personal profile and GitHub auth doesn't go between them.