|
| 1 | +# GitSwitch |
| 2 | + |
| 3 | +A tiny tool to switch between GitHub accounts using the `gh` CLI and configure Git user settings. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Switch GitHub accounts with `gh auth switch`. |
| 8 | +- Set global or local (`--single`) Git user.name and user.email. |
| 9 | +- Support for custom email (`--email`) and hostname (`--hostname`). |
| 10 | +- Unset local Git settings with `--unset-single`. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +### Automatic Installation/Update |
| 15 | + |
| 16 | +Run one of the following commands to download and execute the installer: |
| 17 | + |
| 18 | +Using `curl`: |
| 19 | + |
| 20 | +```bash |
| 21 | +curl -fsSL https://git.new/gitswitch | bash |
| 22 | +``` |
| 23 | + |
| 24 | +Using `wget`: |
| 25 | + |
| 26 | +```bash |
| 27 | +wget -qO- https://git.new/gitswitch | bash |
| 28 | +``` |
| 29 | + |
| 30 | +This installs `gitswitch` to `/usr/local/bin` or `$HOME/.local/bin` and sets up dependencies (`gh`, `jq`). |
| 31 | + |
| 32 | +### Manual Installation |
| 33 | + |
| 34 | +In case the automatic installer fails: |
| 35 | + |
| 36 | +1. **Download the script**: |
| 37 | + |
| 38 | + ```bash |
| 39 | + curl -fsSL "https://git.new/git-switch" -o gitswitch.sh |
| 40 | + ``` |
| 41 | + |
| 42 | + or |
| 43 | + |
| 44 | + ```bash |
| 45 | + wget -qO gitswitch.sh "https://git.new/git-switch" |
| 46 | + ``` |
| 47 | + |
| 48 | +2. **Make it executable**: |
| 49 | + |
| 50 | + ```bash |
| 51 | + chmod +x gitswitch.sh |
| 52 | + ``` |
| 53 | + |
| 54 | +3. **Move to a bin directory**: |
| 55 | + |
| 56 | + ```bash |
| 57 | + sudo mv gitswitch.sh /usr/local/bin/gitswitch |
| 58 | + ``` |
| 59 | + |
| 60 | + or |
| 61 | + |
| 62 | + ```bash |
| 63 | + mv gitswitch.sh $HOME/.local/bin/gitswitch |
| 64 | + ``` |
| 65 | + |
| 66 | +4. **Ensure dependencies**: Install `git`, `gh`, and `jq` using your package manager (e.g., `apt`, `dnf`, `brew`). |
| 67 | + |
| 68 | +5. **Add to PATH** (if using `$HOME/.local/bin`): |
| 69 | + |
| 70 | + ```bash |
| 71 | + echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc |
| 72 | + source ~/.bashrc |
| 73 | + ``` |
| 74 | + |
| 75 | +## Usage |
| 76 | + |
| 77 | +```bash |
| 78 | +gitswitch [--single] [--hostname <host>] [--email <email>] <username> |
| 79 | +gitswitch --unset-single |
| 80 | +gitswitch -h | --help |
| 81 | +``` |
| 82 | + |
| 83 | +- `<username>`: GitHub username to switch to. |
| 84 | +- `--single`: Apply settings to the current repository only. |
| 85 | +- `--unset-single`: Remove local Git settings. |
| 86 | +- `--hostname`: Specify GitHub instance (default: github.com). |
| 87 | +- `--email`: Use a custom email instead of the default noreply email. |
| 88 | + |
| 89 | +## Examples |
| 90 | + |
| 91 | +Switch to a global GitHub account: |
| 92 | + |
| 93 | +```bash |
| 94 | +gitswitch myusername |
| 95 | +``` |
| 96 | + |
| 97 | +Switch for the current repository only: |
| 98 | + |
| 99 | +```bash |
| 100 | +gitswitch --single myusername |
| 101 | +``` |
| 102 | + |
| 103 | +Use a custom email and hostname: |
| 104 | + |
| 105 | +```bash |
| 106 | +gitswitch --hostname github.company.com --email user@company.com myusername |
| 107 | +``` |
| 108 | + |
| 109 | +Unset local repository settings: |
| 110 | + |
| 111 | +```bash |
| 112 | +gitswitch --unset-single |
| 113 | +``` |
| 114 | + |
| 115 | +## Notes |
| 116 | + |
| 117 | +- Ensure you are logged in with `gh auth login -u <username> -h <hostname>` before switching. |
| 118 | +- Local option (`--single`) only affects the current repository's git user settings; Still the `gh` user change applies globally (even if `--single` is used). |
| 119 | + |
| 120 | +## License |
| 121 | + |
| 122 | +Licensed under the MIT License. See [LICENSE](LICENSE) for details. |
0 commit comments