Skip to content

Instantly share code, notes, and snippets.

@ohze
Created July 24, 2017 06:51
Show Gist options
  • Save ohze/5456e17a3204234eb43f91e5b03a697c to your computer and use it in GitHub Desktop.
Save ohze/5456e17a3204234eb43f91e5b03a697c to your computer and use it in GitHub Desktop.
specify ssh-key with git command
#!/bin/sh
# The MIT License (MIT)
# Copyright (c) 2013 Alvin Abad
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 "$@"
@ohze
Copy link
Author

ohze commented Jul 24, 2017

@ohze
Copy link
Author

ohze commented Jul 24, 2017

sudo wget -O /usr/local/bin/git.sh https://gist.githubusercontent.com/ohze/5456e17a3204234eb43f91e5b03a697c/raw/
sudo chmod a+x /usr/local/bin/git.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment