git-switch

GitSwitch

A tiny tool to switch between GitHub accounts using the gh CLI and configure Git user settings.

Features

Installation

Automatic Installation/Update

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).

Manual Installation

In case the automatic installer fails:

  1. 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"
    
  2. Make it executable:

    chmod +x gitswitch.sh
    
  3. Move to a bin directory:

    sudo mv gitswitch.sh /usr/local/bin/gitswitch
    

    or

    mv gitswitch.sh $HOME/.local/bin/gitswitch
    
  4. Ensure dependencies: Install git, gh, and jq using your package manager (e.g., apt, dnf, brew).

  5. Add to PATH (if using $HOME/.local/bin):

    echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
    source ~/.bashrc
    

Usage

gitswitch [--single] [--hostname <host>] [--email <email>] <username>
gitswitch --unset-single
gitswitch -h | --help

Examples

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

Notes

License

Licensed under the MIT License. See LICENSE for details.