logoalt Hacker News

Gitas – A tool for Git account switching

53 pointsby letmutexlast Tuesday at 8:51 AM41 commentsview on HN

Comments

Kwpolskatoday at 9:33 AM

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 = [email protected]

    [remote "origin"]
    url = github.com-work:Work/Widget.git
show 8 replies
djoldmantoday at 5:31 PM

For the folks looking at tools to help manage personal and work identities on the same computer: don't.

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.

show 1 reply
eqvinoxtoday at 11:58 AM

You can put [user] blocks in repos, i.e.

  /some/where $ head .git/config
  [user]
   email = [email protected]
   name = My 'nick' Name
Doesn't tie into your SSH key though, if you need that.
show 1 reply
sevensortoday at 12:00 PM

Github account switching. A git account is not an idea that makes sense.

show 2 replies
rgoultertoday at 9:09 AM

For the use case of "use different accounts / configs for different directories", git's config has includeIf.

sigmonsaystoday at 2:31 PM

Feel free to have your own workflow but git already addresses this tools entire purpose with includeIf.

what does this address that includeIf does not?

lasgawetoday at 4:42 PM

This is nice! This was a problem I faced a few years ago at my job. What I did was create a custom Bash function to switch Git accounts and add it to my .bashrc file. I love this. I’ll give it a try.

teeraytoday at 2:36 PM

When did using a single per-machine SSH key on a Yubikey become so dirty in the eyes of these enterprises?

show 1 reply
dvratiltoday at 10:53 AM

I used to have a git post-checkout hook that set the repo identity based on the repo origin url [0] on checkout - maybe there's some post-clone hook these days, but 10 years ago when I wrote it there was only post-checkout hook.

[0] https://www.dvratil.cz/2015/12/git-trick-%23628-automaticall...

PunchyHamstertoday at 1:40 PM

you can have per repo and per directory git config via git conditional includes

    [includeIf "hasconfig:remote.*.url:https://*.github.com/**"]
    path = /home/xani/src/gh/.gitconfig
show 1 reply
7777777philtoday at 9:31 AM

Lovley, was looking for exactly that for some time. Will definitely try it, thanks for sharing!

aditya24rajtoday at 12:16 PM

GitHub CLI has a command - gh auth switch. It makes it really easy to switch between GitHub accounts. I also wrote a small blog/guide about it- https://aditya24raj.github.io/blogd/using-multiple-github-ac...

nsonhatoday at 4:38 PM

what does this do more than gh switch? I would rather something that automatically picks the right user based on the org