Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulegradie/ddce0bfb1f7bfb3754acc0b6f2a9affe to your computer and use it in GitHub Desktop.
Save paulegradie/ddce0bfb1f7bfb3754acc0b6f2a9affe to your computer and use it in GitHub Desktop.
Bash function to help manage multiple github identities in your ssh config
#~/.ssh/config
_____________________________________________________________________________
# Instructions:
# ---------------------------------------------
# the way this works is that you have to use the Host value with the ssh call
# Host="github.com-paulegradie"
# git clone git@${Host}:paulegradie/SeqPyPlot.git
# The default here is github.com - this is what comes with the copy/paste from github when you click
# the clone or download button.
# ----------------------------------------------
Host *
IdentitiesOnly yes
AddKeysToAgent yes
TCPKeepAlive yes
Host github.com-paulegradie
HostName github.com
User git
IdentityFile ~/.ssh/paulegradie_id_rsa
Host github.com-gradieml
HostName github.com
User git
IdentityFile ~/.ssh/gradieml_id_rsa
_____________________________________________________________________________
#~/.functions
clone () {
# set these to match the Host in the config
gml="gihub.com-gradieml"
peg="github.com-paulegradie"
originalstring=${1} # grabs the first command line arg
itemtoreplace="github.com" # This is what we are replacing with the vars above
if [[ ${2} == "octo" ]];
then
echo "Cloning from Octopus Deploy"
newhost=${originalstring/$itemtoreplace/$peg} # find/replace
git clone ${newhost} # call git clone on the repo
elif [[ ${2} == "peg" ]];
then
echo "Cloning from paulegradie"
newhost=${originalstring/$itemtoreplace/$peg}
git clone ${newhost}
elif [[ ${2} == "gml" ]];
then
echo "Cloning from gradieml"
newhost=${originalstring/$itemtoreplace/$gml}
git clone ${newhost}
else
echo "Usage: clone {repo-link} suffix"
echo "Suffix one of [octo, peg, or gml"
echo ""
echo "e.g. clone git@github.com:paulegradie/SeqPyPlot.git peg"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment