Use multiple GitHub accounts a single machine

It so happens a lot of people are mixing their work- and personal development machines, especially when doing side projects in their spare time which are somewhat work-related.
At least, this is the case for me as I’m using GitHub both for work & personal stuff nowadays.

On my personal machine, I’ve set up Git to work with my personal e-mail address & SSH keys.
On my work machine, I’ve set it up to run with my work account.
Because of this, whenever I commit a change this configured account will be used and I don’t want my corporate account to show up in my side projects, and vice-versa.

Lucky for me, there are a couple of people on Stack Overflow who have similar setups and were also wondering how to fix this. I’m quite happy with the answers posted to Kevin Whitaker’s question.

There are answers on how to do this with SSH keys, which is probably the best option.

However, most repositories on my machine are set up with HTTPS, so the answer from Greg Leszek is the best for my scenario.

He mentions that you first have to change the origin URL to have your username in the URI if this isn’t the case already.
Afterward, you can set the user details you need to use for this repository.

# Sets user for this Git repository
git remote set-url origin https://[email protected]/Jandev/minifier.git
# Setting the user details for the current repository
git config user.name "Jan de Vries"
git config user.email [email protected]

The above example is using my URL Minifier repository.

Yes I know, this is a bit of a copy-paste post from the Stack Overflow answer, but by posting on it over here I’m able to find it later on more easily.


Share

comments powered by Disqus