Skip to content

Instantly share code, notes, and snippets.

@cr0wg4n
Last active March 28, 2024 04:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cr0wg4n/39e691d5f2140bce641448b0f56e6a9e to your computer and use it in GitHub Desktop.
Save cr0wg4n/39e691d5f2140bce641448b0f56e6a9e to your computer and use it in GitHub Desktop.
A Bash script to interchange multiple GitHub users in a unique machine
#!/bin/bash
gh_user="${1:-Nothing}"
if [ "$gh_user" == 'USERNAME_1' ]; then
ssh-add -D
git config --global user.email "USERNAME_1_EMAIL"
ssh-add /PRIVATE_KEY_PATH/.ssh/github-USERNAME_1
elif [ "$gh_user" == 'USERNAME_2' ]; then
ssh-add -D
git config --global user.email "USERNAME_2_EMAIL"
ssh-add /PRIVATE_KEY_PATH/.ssh/github-USERNAME_2
else
echo 'Nothing was applied'
exit 1
fi
echo "$gh_user applied!"
git config user.email
ssh -T git@github.com
exit 0
# TO USE
# ./switch-github-user.sh USERNAME_1
@pedroalmeida415
Copy link

Works great!

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