Last active
July 6, 2016 01:03
-
-
Save auycro/14d1ecafeb647238f015ef9c1e7ba733 to your computer and use it in GitHub Desktop.
git with ssh key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The MIT License (MIT) | |
# Copyright (c) 2013 Alvin Abad | |
# https://alvinabad.wordpress.com/2013/03/23/how-to-specify-an-ssh-key-file-with-the-git-command/ | |
# HOW TO USE:: | |
# git.sh -i ~/.ssh/userkey.pem clone [email protected]:/git/repo.git | |
if [ $# -eq 0 ]; then | |
echo "Git wrapper script that can specify an ssh-key file | |
Usage: | |
git.sh -i ssh-key-file git-command | |
" | |
exit 1 | |
fi | |
# remove temporary file on exit | |
trap 'rm -f /tmp/.git_ssh.$$' 0 | |
if [ "$1" = "-i" ]; then | |
SSH_KEY=$2; shift; shift | |
echo "ssh -i $SSH_KEY \$@" > /tmp/.git_ssh.$$ | |
chmod +x /tmp/.git_ssh.$$ | |
export GIT_SSH=/tmp/.git_ssh.$$ | |
fi | |
# in case the git command is repeated | |
[ "$1" = "git" ] && shift | |
# Run the git command | |
git "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment