@variant96/git-account-switcher
v1.0.1
Published
Interactive CLI tool for managing and switching between multiple git and GitHub CLI accounts
Downloads
192
Maintainers
Readme
Git Account Switcher
A powerful, interactive CLI tool that helps you manage and switch between multiple git and GitHub CLI accounts seamlessly.
Features
- Auto-detection - Automatically detects existing git configs and GitHub CLI accounts
- Interactive Setup - User-friendly wizard for first-time configuration
- JSON Configuration - Stores account settings in
~/.git-accounts.json - Easy Switching - Switch between accounts with a single command
- Colored Output - Clear, colorful terminal output for better readability
- Validation - Comprehensive error checking and user feedback
- NPM Package - Install globally and use anywhere
Installation
Install globally using npm:
npm install -g @variant96/git-account-switcherOr using yarn:
yarn global add @variant96/git-account-switcherPrerequisites
- Node.js - Version 14.0.0 or higher
- git - Install Git
- gh (GitHub CLI) - Install GitHub CLI (optional)
Note: You can add accounts without GitHub CLI authentication initially. The tool will allow you to enter your GitHub username manually and you can authenticate with
gh auth loginlater.
Quick Start
After installation, run the setup wizard:
git-switch setupThe wizard will guide you through adding your first account. Then start switching:
# Switch to an account (local - current repo only)
git-switch switch personal
# Switch to an account (global)
git-switch switch work --globalUsage
Commands
Setup
Run the interactive setup wizard:
git-switch setupSwitch Accounts
# Switch to an account (local scope - current repo only)
git-switch switch personal
# Switch to an account (global scope)
git-switch switch work --global
git-switch switch work -gList Accounts
git-switch listShow Current Status
git-switch currentAdd New Account
git-switch addYou'll be prompted to enter:
- Account name (e.g., "personal", "work", "client")
- Git name
- Git email
- GitHub username
Remove Account
git-switch remove <account-name>Help
git-switch --helpConfiguration File
Accounts are stored in ~/.git-accounts.json:
{
"accounts": [
{
"name": "personal",
"git_name": "John Doe",
"git_email": "[email protected]",
"gh_username": "johndoe"
},
{
"name": "work",
"git_name": "John Doe",
"git_email": "[email protected]",
"gh_username": "johndoe-work"
}
],
"last_used": "personal"
}Examples
Complete Workflow
# First time - run setup
git-switch setup
# List available accounts
git-switch list
# Switch to work account globally
git-switch switch work -g
# Check current configuration
git-switch current
# Switch to personal account for current repo only
git-switch switch personal
# Add a new client account
git-switch addMultiple GitHub Accounts
If you have multiple GitHub accounts, you need to authenticate each one with GitHub CLI:
# Login with first account
gh auth login
# Login with second account (adds to existing)
gh auth loginThe tool will automatically detect all authenticated accounts during setup.
How It Works
- Account Storage: Accounts are stored in a JSON file with git and GitHub CLI credentials
- Git Switching: Uses
git configto set user.name and user.email (local or global) - GitHub CLI Switching: Uses
gh auth switchto change the active GitHub account - Synchronization: Both git and gh are switched together to keep them in sync
Troubleshooting
"No accounts configured yet"
Run the setup wizard:
git-switch setup"Failed to switch gh account"
Make sure you've authenticated the GitHub account:
gh auth loginConfig file location
The configuration is stored at ~/.git-accounts.json. You can:
- View it:
cat ~/.git-accounts.json - Delete it to start fresh:
rm ~/.git-accounts.json
"command not found: git-switch"
If you installed the scoped package, make sure npm's global bin directory is in your PATH:
npm config get prefixThe binaries should be in <prefix>/bin.
Development
Local Development
Clone the repository and install dependencies:
git clone https://github.com/eliotalders0n/git-account-switcher.git
cd git-account-switcher-npm
npm installLink the package locally:
npm linkNow you can use git-switch command locally for testing.
Project Structure
git-account-switcher-npm/
├── bin/
│ └── git-switch.js # CLI executable
├── src/
│ ├── config.js # Configuration management
│ ├── git-operations.js # Git and GitHub CLI operations
│ ├── interactive.js # Interactive prompts and setup wizard
│ └── index.js # Main module exports
├── package.json
└── README.mdContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
eliotalders0n
- GitHub: @eliotalders0n
Support
If you find this tool helpful, please consider:
- Starring the repository
- Reporting bugs
- Suggesting new features
- Sharing with others
Made by developers, for developers
