loading...

Multiple GitHub accounts in the same computer

ech0server profile image GaMa ・2 min read

Due to work I faced the need of using two or more GitHub accounts, sometimes I need to use the accounts in the same machine. I've been trying to use the following solution:

https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574

However I couldn't make it to work, by the time I was experimenting with Docker and I got the idea of using a container to just push my changes. So far I haven't identify any security related problems, obviously never expose the container to internet just start it push your changes and stop it, or script it to launch it add the new ssh keys to github push then destroy the container.

The solution is quite simple, start a new container from the image I created in an earlier post: Creating the Docker image

First of all pull the image:

docker pull drverboten/multigitaccount

Then create a new container from the image, but add the path of the source code or any other resource you want to add to your repo as a volume with the -v option:

docker run -it --name gitpub -v /home/[user]/[path to workspace]:/workspace drverboten/multigitaccount /bin/sh

After the container is running, create a new ssh key with the following command:

ssh-keygen -t rsa -b 4096 -C "[email]"

Copy your key to the clipboard you can just cat and copy the text:

cat ~/.ssh/id_rsa.pub

Add the key to GitHub

GitHub

Back in the container configure git:

git config --global user.email "[email]"
git config --global user.name "[username]"

And you are all set, just push to GitHub as you normally do, it will post as the configured user.

👻✌️

Posted on by:

Discussion

markdown guide
 

While it seems like a solution, I think it is not that elegant. You could setup a got user per directory: dev.to/maxlmator/maintaining-diffe...

And you can manage the SSH keys with a SSH config file. I couldn't find the resource I used for that, but if you are interested in that I can write a small post about it. Should also help other people at that same time :)

 

Thank you, if you can write it, it would be great. I came with this "solution" because I did not wanted to spend time looking why I couldn't make it work in any other way I could google, so I went with what I knew :)