Last active
June 6, 2023 16:17
-
-
Save Fordi/734a0e5bebbe98262e78f0f8de3a7a99 to your computer and use it in GitHub Desktop.
Identity config for git
This file contains 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
# 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