A tiny tool to switch between GitHub accounts using the gh CLI and configure Git user settings.
gh auth switch.--single) Git user.name and user.email.--email) and hostname (--hostname).--unset-single.Run one of the following commands to download and execute the installer:
Using curl:
/bin/bash -c "$(curl -fsSL https://github.com/dominusmmp/git-switch/raw/master/install.sh)"
Using wget:
/bin/bash -c "$(wget -qO- https://github.com/dominusmmp/git-switch/raw/master/install.sh)"
This installs gitswitch to /usr/local/bin or $HOME/.local/bin and sets up dependencies (gh, jq).
In case the automatic installer fails:
Download the script:
curl -fsSL "https://github.com/dominusmmp/git-switch/raw/master/gitswitch.sh" -o gitswitch.sh
or
wget -qO gitswitch.sh "https://github.com/dominusmmp/git-switch/raw/master/gitswitch.sh"
Make it executable:
chmod +x gitswitch.sh
Move to a bin directory:
sudo mv gitswitch.sh /usr/local/bin/gitswitch
or
mv gitswitch.sh $HOME/.local/bin/gitswitch
Ensure dependencies: Install git, gh, and jq using your package manager (e.g., apt, dnf, brew).
Add to PATH (if using $HOME/.local/bin):
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
source ~/.bashrc
gitswitch [--single] [--hostname <host>] [--email <email>] <username>
gitswitch --unset-single
gitswitch -h | --help
<username>: GitHub username to switch to.--single: Apply settings to the current repository only.--unset-single: Remove local Git settings.--hostname: Specify GitHub instance (default: github.com).--email: Use a custom email instead of the default noreply email.Switch to a global GitHub account:
gitswitch myusername
Switch for the current repository only:
gitswitch --single myusername
Use a custom email and hostname:
gitswitch --hostname github.company.com --email user@company.com myusername
Unset local repository settings:
gitswitch --unset-single
gh auth login -u <username> -h <hostname> before switching.--single) only affects the current repository’s git user settings; Still the gh user change applies globally (even if --single is used).Licensed under the MIT License. See LICENSE for details.