I use multiple GitHub logins to host multiple GitHub Pages User Sites:
- https://github.com/djhmateer - my main GH account which hosts davemateer.com
- https://github.com/penhemingway - my 2nd account penhemingway.github.io
- https://github.com/qjhemingway - my 3rd account [qjhemingway.github.io] (https://qjhemingway.github.io)
Importantly I use HTTPS, which is now the norm, rather than SSH Keys
Multiple GH Logins
Make sure your version of git is up to date. As of 28th July 2019 it is 2.22.0. and you’ve got Git Credenital Manager installer. This is for Windows, but I’m sure the *nix concepts will be the same.
We want Git Credential Manager.
Delete current cache of GitHub passwords
Credential Manager from the start key on Windows and delete any cached passwords.
Edit the git config file
In a repo requiring your 2nd GH account:
So I specify the name of any non-default GH accounts, and add useHttpPath.
I prefer manually editing the .git/config file. To see the hidden file in VS Code, File, Preferences, Settings, search for exclude. Delete the .git setting.
This is another way of doing the above.
git clone https://github.com/penhemingway/penhemingway.github.io.git git remote -v # we get #origin https://github.com/penhemingway/penhemingway.github.io.git (fetch) #origin https://github.com/penhemingway/penhemingway.github.io.git (push) # add in the username in front of github.com git remote set-url origin https://email@example.com/penhemingway/penhemingway.github.io.git git remote -v # view the changes #origin https://firstname.lastname@example.org/penhemingway/penhemingway.github.io.git (fetch) #origin https://email@example.com/penhemingway/penhemingway.github.io.git (push) # update httpPath # any credentials used should be associated with full repository path, not the entire domain eg github.com default (our main account) git config credential.useHttpPath true
Now login with the 2nd account and it works
What have we done
And looking at the Windows Credential Manager (after you’ve logged into your default GH account again) you can see our 2 cached passwords.
So now I don’t notice I’m working with multiple GitHub Accounts on one machine.