I use shell scripts to switch me to whatever account I want to be "active". Essentially you start from a fresh start, get one account configured properly and working, then move the these files to a name with the proper prefix. From then on you can use the command "github", or "gitxyz" to switch:
# my github script
cd ~/.ssh
if [ -f git_dhoerl -a -f git_dhoerl.pub -a -f config_dhoerl ]
then
;
else
echo "Error: missing new files"
exit 1
fi
# Save a copy in /tmp, just in case
cp id_rsa /tmp
cp id_rsa.pub /tmp
cp config /tmp
echo "Saved old files in /tmp, just in case"
rm id_rsa
rm id_rsa.pub
rm config
echo "Removed current links/files"
ln git_dhoerl id_rsa
ln git_dhoerl.pub id_rsa.pub
ln config_dhoerl config
git config --global user.email "dhoerl@<company>.com"
git config --global github.user "dhoerl"
git config --global github.token "whatever_it_is"
ssh-add -D
I've had great luck with this. I also created a run script in Xcode (for you Mac users) so it would not build my project unless I had the proper setting (since its using git):
Run Script placed after Dependencies (using /bin/ksh as the shell):
if [ "$(git config --global --get user.email)" != "dhoerl@<company>.com" ]
then
exit 1
fi
EDIT: added tests for new files existence and copying old files to /tmp to address comment by @naomik below.