Skip to content

Instantly share code, notes, and snippets.

@rpetrich
Last active June 1, 2017 14:44
Show Gist options
  • Save rpetrich/cd6b99256766d80fc127c172d7579344 to your computer and use it in GitHub Desktop.
Save rpetrich/cd6b99256766d80fc127c172d7579344 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$GIT_AUTHOR_EMAIL" ]; then
GIT_AUTHOR_EMAIL=`git config --get user.email`
fi
if [[ `uname` != Darwin ]]; then
IDENTITY=`readlink -f ~/.ssh/$GIT_AUTHOR_EMAIL`
elif which -s greadlink; then
IDENTITY=`greadlink -f ~/.ssh/$GIT_AUTHOR_EMAIL`
else
# No modern readlink with -f support, symlinks must be absolute paths :'(
IDENTITY=`readlink ~/.ssh/$GIT_AUTHOR_EMAIL`
fi
if [ -f "$IDENTITY" ]; then
exec ssh -o IdentitiesOnly=yes -i "$IDENTITY" $*
fi
echo "No symlink to a private key found for $GIT_AUTHOR_EMAIL at ~/.ssh/$GIT_AUTHOR_EMAIL, using default" >&2
exec ssh $*
brew upgrade git && git --version
# Requires git 2.10 and later
git config --global core.sshCommand ~/bin/github-autodetect.sh
# Primary Identity
ln -s $USER/.ssh/id_rsa $USER/.ssh/rpetrich@gmail.com
git config --global user.email rpetrich@gmail.com
# Secondary Identity
ln -s $USER/.ssh/alterego_rsa $USER/.ssh/alter@ego.com
GIT_AUTHOR_EMAIL=alter@ego.com git clone git@github.com:alter-ego/alter_project.git
cd alter_project
git config user.email alter@ego.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment