If you also need to juggle between work accounts and your own personal Git you might get yourself dealing with customizing Git configuration for each individual repository.
In this article, I am going to share a directory structure suggestion that combined with conditional include will help you achieve a more efficient way that works on any Unix-like (Mac, Linux etc.) machine.
For the remainder of this article we are going to suppose you have two work accounts and a single personal account.
Using SSH keys allows you to avoid typing username and password for Git operations greatly speeding things up.
In order to create one key for each of the accounts you are going to use the ssh-keygen command, make sure that when asked for a passphrase you leave it blank (just press Enter twice):
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "remi.byers@protonmail.com" -f "personal"
$ ssh-keygen -t rsa -C "remi.b@work1.io" -f "work1"
$ ssh-keygen -t rsa -C "r.byers@work2.com" -f "work2"
The username is intended to be fictional.
Once finished the result will be three pairs of keys (public and private) for each account, like so:
$ ls -la ~/.ssh
total 64
drwx------ 10 remb staff 320 Jul 30 11:02 .
drwxr-xr-x+ 31 remb staff 992 Aug 5 16:01 ..
-rw------- 1 remb staff 434 Jul 23 08:51 config
-rw------- 1 remb staff 2602 Jul 22 13:43 personal
-rw-r--r-- 1 remb staff 567 Jul 22 13:43 personal.pub
-rw------- 1 remb staff 2610 Jul 23 08:43 work1
-rw-r--r-- 1 remb staff 574 Jul 23 08:43 work1.pub
-rw------- 1 remb staff 2610 Jul 22 13:44 work2
-rw-r--r-- 1 remb staff 574 Jul 22 13:44 work2.pub
-rw-r--r-- 1 remb staff 1718 Jul 31 15:20 known_hosts
The contents of each public key (the files ending with .pub) needs to be added on the corresponding Git account.
#git #github #keys