A tiny tool to switch between GitHub accounts using the gh
CLI and configure Git user settings.
- Switch GitHub accounts with
gh auth switch
. - Set global or local (
--single
) Git user.name and user.email. - Support for custom email (
--email
) and hostname (--hostname
). - Unset local Git settings with
--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
, andjq
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
- Ensure you are logged in with
gh auth login -u <username> -h <hostname>
before switching. - Local option (
--single
) only affects the current repository's git user settings; Still thegh
user change applies globally (even if--single
is used).
Licensed under the MIT License. See LICENSE for details.