For my workflow I opted to create another Github account to use it for work projects. In order to juggle my work and personal Github accounts, I’ve set up git cli with different ssh keys. I’ve tried using the same ssh key for both Github accounts but the key is rejected if it has been used on another accounts. To get arround this I’m using the folwing setup. I am using a Macbook but it can work on Windows WSL though I haven’t tested it.
How I’ve set it up
- Create a copy of
~/.ssh/config
and name itconfig.personal
and respectivelyconfig.work
mv ~/.ssh/config ~/.ssh/config.personal && mv ~/.ssh/config ~/.ssh/config.work
- Update the keys respectively for each
.ssh/config
work and personal
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
- edit your
~/.bashrc
or~/.zshrc
or~/.bash_profile
and paste in the below script.
git-switch(){
echo "Choose your profile"
select opt in Personal Work Quit;
do
case $opt in
Personal)
echo "Using $opt profile"
cp ~/.ssh/config.personal ~/.ssh/config
break
;;
Work)
echo "Using $opt profile"
cp ~/.ssh/config.work ~/.ssh/config
break
;;
quit)
break
;;
*)
echo "Invalid option $REPLY"
;;
esac
done
}
- Source your config from a terminal window
source ~/.bashrc
- Now if you run
git-switch
in your terminal you should be presented with a choice of profile
Choose your profile
1) Personal 2) Work 3) Quit
?#
- Feel free to go back and edit the script to add as many accounts you want
Lukeworm regards,