Skip to content

Instantly share code, notes, and snippets.

@cr0wg4n
Last active October 23, 2024 23:58
Show Gist options
  • 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 [email protected]
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