Created
June 12, 2024 16:45
-
-
Save atereshkov/d8c968ed685cf943b5d7f72d66c9ece9 to your computer and use it in GitHub Desktop.
A bash script to switch between multiple github users (ssh keys)
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
#!/bin/bash | |
gh_user="${1:-Nothing}" | |
if [ "$gh_user" == 'USER1' ]; then | |
ssh-add -D | |
git config --global user.email "USERNAME_1_EMAIL" | |
ssh-add ~/.ssh/id_ed1 | |
elif [ "$gh_user" == 'USER1' ]; then | |
ssh-add -D | |
git config --global user.email "USERNAME_2_EMAIL" | |
ssh-add ~/.ssh/id_ed2 | |
else | |
echo 'Nothing was applied' | |
exit 1 | |
fi | |
echo "$gh_user applied!" | |
# git config user.email | |
ssh -T [email protected] | |
exit 0 | |
# Instruction: | |
# First of all, enter `chmod +x switch-github-user.sh` after downloading the file. | |
# Then just use the script: `./switch-github-user.sh USER1`, where `USER1` is your gh_user specified. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment