Skip to content

Instantly share code, notes, and snippets.

@Fordi
Last active June 6, 2023 16:17
Show Gist options
  • Save Fordi/734a0e5bebbe98262e78f0f8de3a7a99 to your computer and use it in GitHub Desktop.
Save Fordi/734a0e5bebbe98262e78f0f8de3a7a99 to your computer and use it in GitHub Desktop.
Identity config for git
# For easily managing your SSH identity for github.
#
# 1. Source this script in your .profile or .bashrc
# 2. Run `git config user.identity=/path/to/keyfile` in each repository you want to be using a non-default SSH identity
# 3. Git around as usual.
function git() {
local git="$(which git)"
local cmd=("$git" "${@}")
local ident="$("$git" config user.identity)"
if [[ "$?" != 0 || "$ident" == "" ]]; then
"${cmd[@]}"
else
GIT_SSH_COMMAND='ssh -i '"$ident"' -o IdentitiesOnly=yes' "${cmd[@]}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment