Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created March 30, 2017 03:56
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 17twenty/dfd49a0193674dd8d7d84539a32bc24d to your computer and use it in GitHub Desktop.
Save 17twenty/dfd49a0193674dd8d7d84539a32bc24d to your computer and use it in GitHub Desktop.
Wrapper script that can specify an ssh-key file with the Git command
#!/bin/bash
#-------------------------------------------------------------------------------
# Wrapper script that can specify an ssh-key file with the Git command
#
# The MIT License (MIT) - http://opensource.org/licenses/MIT
# Copyright (c) 2013 Alvin Abad
#-------------------------------------------------------------------------------
if [ $# -eq 0 ]; then
echo "Wrapper script that can specify an ssh-key file with the Git command
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