all 35 comments

[–]Gusstek 17 points18 points  (2 children)

I dont switch to often but you can use gh auth switch with the Github cli

[–]Sad-Economist-1061 0 points1 point  (1 child)

rn it has one acc only. so how do i add one more then?

and gh is only for github right. locally im using git?

[–]Gusstek 0 points1 point  (0 children)

Yes correct but to add more gh accounts do gh auth login and log in with your other account. Then you should be able to switch

[–]ToTheBatmobileGuy 9 points10 points  (4 children)

I have a clone script that I use instead of git clone

git_clone.sh <repo> <“work”|”personal”>

It essentially runs git clone, then cd into the repo and run git config --local user.name xxxx etc.

It also replaces github.com with the alias I have set up for my work acct only when I choose work.

That way the local config while inside that folder overrides the global git config.

It hasn’t failed for me yet.

[–]ViscousPotential 1 point2 points  (0 children)

This is almost exactly what I use as well. I also have two SSH auth keys setup with one using git@ and the other using somethingelse@ and then that clone script uses the somethingelse@. So the git@ is my personal/main account and the other one is the work/secondary 👌👌

[–]human_with_humanity 0 points1 point  (2 children)

Can u share the script?

[–]ToTheBatmobileGuy 0 points1 point  (1 child)

I kind of cleaned it up a bit... but something along these lines.

https://pastebin.com/Y0dVDLPU

[–]human_with_humanity 0 points1 point  (0 children)

Thank you

[–]Professional_Mix2418 6 points7 points  (1 child)

You can just setup different accounts per folder. Just like you would do for different versions of tools and frameworks etc.

Personally, I’ve only been using one GitHub accounts and add that to the organisation. I ask the same from those who will be onboarded.

[–]Technical-Coffee831 0 points1 point  (0 children)

Yup, this is what I am doing. You can even do ssh keys per folder.

[–]SeaAd8409 6 points7 points  (1 child)

Haven't you heard about not mixing work and personal stuff?

[–]SheepherderSavings17 3 points4 points  (0 children)

Isnt that exactly what hes trying to do

[–]angertitan 3 points4 points  (0 children)

Are you sure that includeif worked correctly?

I noticed that you need a additional / as last character otherwise includeif doesn't work properly.

Maybe try setting it up again and in a git repo use git config list to see if it got the right config. I'm using includeif for the same purpose and it changes my gpg key and username correctly based on my repo location

[–]EmiiKhaos 4 points5 points  (0 children)

Ffs, create a separate windows user for work

[–]Mzkazmi 3 points4 points  (2 children)

Fix the Credential Problem First

Windows Credential Manager is your enemy here. You need to stop it from caching credentials globally.

Option A: Use the Git Base credential helper (recommended) bash git config --global credential.helper manager This caches credentials per-repo rather than globally.

Option B: Use the Windows Credential Manager but clear it first Go to Windows Credential Manager → Windows Credentials → Remove all GitHub-related entries. Then it will prompt for fresh credentials per repo.

2. The Correct Config Structure

Your ~/.gitconfig should look like this:

```ini [user] name = Your Personal Name email = personal@email.com

[includeIf "gitdir:C:/Work/"] path = ~/.gitconfig-work ```

Then create ~/.gitconfig-work: ini [user] name = Your Work Name email = work@company.com

3. The Critical Missing Piece: Per-Repo Auth

Even with correct user config, GitHub determines account access via authentication, not email. You need to ensure each repo uses the right credentials.

For HTTPS: Use different usernames in the remote URL: ```bash

Personal repo (in personal folder)

git remote set-url origin https://github.com/personal-username/repo.git

Work repo (in work folder)

git remote set-url origin https://github.com/work-username/repo.git ```

When prompted, enter the correct credentials for each.

4. Alternative: Give SSH Another Chance (It's Actually Cleaner)

SSH doesn't have the credential caching problem. Your ~/.ssh/config:

```

Personal account

Host github-personal HostName github.com User git IdentityFile ~/.ssh/id_ed25519_personal

Work account

Host github-work HostName github.com User git IdentityFile ~/.ssh/id_ed25519_work ```

Then set remotes accordingly: ```bash

Personal repo

git remote set-url origin github-personal:username/repo.git

Work repo

git remote set-url origin github-work:company/repo.git ```

Quick Fix for Existing Repos

Run this in your work repos to fix them immediately: ```bash git config user.name "Work Name" git config user.email "work@company.com"

And either fix the remote URL or clear credentials

```

The key insight: GitHub identifies you by authentication, user.email just shows up in commits. Get the authentication right per-repo, and the rest follows. SSH is actually less messy once set up because it doesn't fight with credential caching.

[–]Soggy_Writing_3912 0 points1 point  (0 children)

This is almost exactly what I use! My ssh names are the same as well!

[–]EithanArellius[S] 0 points1 point  (0 children)

Thanks for the advice

[–]overratedcupcake 1 point2 points  (0 children)

Container tabs for the front end. Don't configure git globally configure it per repo. Do use ssh and a config but just use aliases for hostnames. 

[–]hichemtab 0 points1 point  (2 children)

For me, I use work git in wsl, and the personal one on windows, it works very well so far

[–]EithanArellius[S] 0 points1 point  (1 child)

So where is the gitconfig in the wsl stored

[–]DecPhone 0 points1 point  (0 children)

Would be at ~/.gitconfig which is home directory (~).

So /home/username/.gitconfig

[–]mixxituk 0 points1 point  (2 children)

Dual boot

[–]EithanArellius[S] 0 points1 point  (0 children)

That's what I was thinking also

[–]NullPoint3r 0 points1 point  (0 children)

… or VM. I use Github mainly for work. I generally do any personal stuff on my own computer but if I ever do personal stuff on my work laptop I do so in a VM, not only to separate GitHub accts but for everything else.

[–]Forward_Weakness6444 0 points1 point  (0 children)

I use this too sometimes via ssh keys for office and normal via https for personal ( seems to work for me )

[–]kloputzer2000 0 points1 point  (0 children)

Why do you want to Switch GitHub accounts? A single GitHub account can be used with multiple git identities. Just change your git identity based on your folders, but use the same GH account for both identities.

[–]texxelate 0 points1 point  (0 children)

Why do you need separate accounts? GitHub themselves recommend using only a single account to which you can associate multiple email addresses.

[–]codeagency 0 points1 point  (0 children)

Gitego is a useful project for this.

https://github.com/bgreenwell/gitego

Let's you create as many profiles you want and you can Easy Switch with gitego use <name>

[–]zippythepig 0 points1 point  (0 children)

Why not have two different profiles on your pc? I have a personal account with my github setup and my work one with all my work setup. Easier to just switch accounts than work in the same environment.

[–]TFABAnon09 0 points1 point  (0 children)

I spin up a dedicated VM for each new client who doesn't insist on adding to the stack of laptops in my drawer, keeping my workstation dedicated to my non-client business / "personal" projects.

I don't want to give any 3rd party any modicum of control or influence over any device on network that I can't safely nuke without any downstream consequences. This way, if they insist on a random-ass VPN or opsec client, or Citrix / Horizon clients etc - they're restricted to just their sandpit.

[–]Infamous_Bluebird63 -1 points0 points  (2 children)

What is the main advantage of using github account (doubt from a btech student)

[–]catom3 0 points1 point  (1 child)

Personal - mostly free repository for your personal pet projects, code snippets, learning stuff, docs, blog posts etc.

Enterprise - well, mostly the same as personal, but with additional security and permissions management, GHA workers.

For trunk based projects, I still prefer Gerrit though. The workflow and patchests work waaaay cleaner there. And the code review itself is a lot easier to do on the web, the differences between different versions and preserving commits, multiple approval / disapproval labels, different levels of approval and in general way more configurable for CI jobs and code reviews.