1157 1105 1301 1997 1685 1563 1209 1590 1337 1914 1358 1524 1780 1687 1759 1117 1946 1093 1970 1594 1808 1497 1089 1210 1320 1967 1554 1523 1312 1595 1675 1185 1798 1116 1947 1053 1289 1204 1994 1478 1082 1909 1218 1466 1117 1934 1031 1587 1686 1317 1950 1330 1252 1794 1120 1813 1832 1822 1626 1957 1306 1281 1930 1957 1963 1050 1087 1446 1753 1070 1377 1701 1627 1501 1936 1921 1199 1418 1451 1747 1381 1070 1907 1548 1914 1581 1405 1478 1696 1019 1230 1185 1612 1104 1920 1251 1856 1682 1101 Multiple Github accounts on a single machine | PHPnews.io

PHPnews.io

Multiple Github accounts on a single machine

Written by Stefan Koopmanschap / Original link on Feb. 7, 2022

I've not used Github a lot anymore in recent times because we've switched to Gitlab some time ago. The main reason for using Github at this point is client work. But sometimes, I still need my account for open source reasons.

For one of the customers I do work for, however, I was asked to create a separate Github account. Now I was running into some issues because the private repositories are now shared with this new account, but by default I'm logged into my own account on the commandline (well, it picks my default key). Searching around I ended up on the site of freeCodeCamp, where Bivil M Jacob shared the solution that ended up working. The solution: Add a configuration file.

The first three steps are pretty standard and now that hard to understand, but the fourth step was new to me. I had no idea this was possible. So I followed the guidance of Bivil and ended up with my own .ssh/config file:

# Skoop, - the default config
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa

# clientskoop
Host client.github.com    
   HostName github.com
   User git
   IdentityFile ~/.ssh/cf_ed25519

I've redacted this example to not include my actual client name. Now, if I want to clone a private repository from my client, all I need to do is:

git clone git@client.github.com:clientname/clientrepo.git

In the above command, note the client.github.com host name that is the same as the Host I defined in the config file. And lo and behold, when I clone in this way I can clone without a problem. It takes the correct key for this specific repository and I can do everything I want: push, pull, etc.

Sometimes the solution is simpler than you would've imagined.

skoop

« Code scanning and Ruby: turning source code into a queryable database - DevTools for Tailwind »