Two scripts that switch this machine between a personal GitHub account and an other GitHub account.
Each run updates git identity, HTTPS credentials, and (if installed) GitHub CLI auth so git clone, git push, and git pull use the selected profile.
| Script | Profile |
|---|---|
switch-personal.sh |
Personal GitHub account |
switch-other.sh |
Other GitHub account |
Shared logic lives in lib/github-switch.sh. Do not run that file directly.
Create a classic personal access token (ghp_...) for each account. Recommended scopes: repo, plus workflow and gist if you need them.
chmod +x switch-personal.sh switch-other.sh
./switch-personal.sh
./switch-other.shEach script asks for:
- Git commit name
- Git commit email
- GitHub username
- Classic PAT (input is hidden)
Credentials are saved under ~/.config/github-account-switcher/ with mode 600. Tokens are never printed and are not stored in this repo.
./switch-personal.sh # switch to personal
./switch-other.sh # switch to otherAfter a switch, the script prints the active user.name, user.email, and github.user.
./switch-personal.sh --setup
./switch-other.sh --setupThis re-prompts for name, email, username, and token, then switches to that profile.
git config --global user.namegit config --global user.emailgit config --global github.user- GitHub HTTPS credentials for
github.comandgist.github.com(macOS Keychain viaosxkeychain, orstoreon Linux) ~/.netrcentries forgithub.com,gist.github.com, andapi.github.comgh auth loginwhen the GitHub CLI is installed- SSH remotes (
git@github.com:andssh://git@github.com/) rewritten to HTTPS so the PAT is used
To keep SSH remotes as SSH instead of rewriting them to HTTPS:
FORCE_GITHUB_HTTPS=0 ./switch-personal.sh~/.config/github-account-switcher/
personal.env # personal name, email, username, token
other.env # other name, email, username, token
active # last profile switched to
This directory is 700. Profile files are 600. They are outside the repo on purpose.
- macOS or Linux
git- Interactive terminal for first-time setup
- A PAT starting with
ghp_(classic) orgithub_pat_(fine-grained)
gh is optional. HTTPS + PAT is enough for clone, push, and pull.
- Do not commit tokens,
.envfiles, or~/.netrc .gitignorealready ignores*.envandaccounts/- Do not paste PATs into chat, issues, or pull requests
- Revoke a token on GitHub if it leaks, then re-run the matching script with
--setup