npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@variant96/git-account-switcher

v1.0.1

Published

Interactive CLI tool for managing and switching between multiple git and GitHub CLI accounts

Downloads

192

Readme

Git Account Switcher

npm version License: MIT Node.js

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-switcher

Or using yarn:

yarn global add @variant96/git-account-switcher

Prerequisites

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 login later.

Quick Start

After installation, run the setup wizard:

git-switch setup

The 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 --global

Usage

Commands

Setup

Run the interactive setup wizard:

git-switch setup

Switch 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 -g

List Accounts

git-switch list

Show Current Status

git-switch current

Add New Account

git-switch add

You'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 --help

Configuration 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 add

Multiple 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 login

The tool will automatically detect all authenticated accounts during setup.

How It Works

  1. Account Storage: Accounts are stored in a JSON file with git and GitHub CLI credentials
  2. Git Switching: Uses git config to set user.name and user.email (local or global)
  3. GitHub CLI Switching: Uses gh auth switch to change the active GitHub account
  4. 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 login

Config 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 prefix

The 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 install

Link the package locally:

npm link

Now 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.md

Contributing

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

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