Skip to content

dankozlowski/git-switcher

Repository files navigation

git-switcher

A terminal UI for toggling between git and GitHub identities. Run it in any repo to see your current git user, SSH key, and GitHub account — then switch to a different profile with a single keystroke.

What it does

When you run git-switcher inside a git repository, it:

  1. Reads your profiles from ~/.config/git-switcher/config.toml
  2. Detects the repo's current identity (git user, SSH key, gh account)
  3. Shows a dashboard with the current state and your available profiles
  4. On selection, sets the local git config, SSH key, and active gh account

Installation

go install github.com/dankozlowski/git-switcher@latest

Or build from source:

git clone https://github.com/dankozlowski/git-switcher.git
cd git-switcher
go build -o git-switcher .

Configuration

Create ~/.config/git-switcher/config.toml:

[[profiles]]
name = "personal"
git_name = "Your Name"
git_email = "you@example.com"
ssh_key = "~/.ssh/id_ed25519"
gh_user = "yourgithub"

[[profiles]]
name = "work"
git_name = "Your Work Name"
git_email = "you@work.com"
ssh_key = "~/.ssh/work_key"
gh_user = "your-work-github"

Each profile needs:

Field Description
name Display label for the profile
git_name Value for user.name
git_email Value for user.email
ssh_key Path to SSH private key (~ is expanded)
gh_user GitHub username for gh auth switch

Usage

cd your-repo
git-switcher

Navigate with arrow keys (or j/k), press Enter to switch, q to quit.

When you switch profiles, git-switcher runs:

git config --local user.name "..."
git config --local user.email "..."
git config --local core.sshCommand "ssh -i <key> -o IdentitiesOnly=yes"
gh auth switch --user <gh_user>

If gh isn't installed or the account isn't logged in, git and SSH settings are still applied — you'll see a warning for the gh step.

Prerequisites

  • Go 1.22+ (to build)
  • git
  • gh (optional, for GitHub account switching)

If using gh, authenticate both accounts first:

gh auth login  # first account
gh auth login  # second account

Project Layout

git-switcher/
├── main.go           Entry point, pre-flight checks, launches TUI
├── config.go         Config file parsing (TOML)
├── detector.go       Reads current repo state (git config, SSH, gh)
├── switcher.go       Applies a profile (git config, SSH, gh commands)
├── tui.go            Bubbletea model, view, update
├── *_test.go         Tests for config, detector, and switcher
├── go.mod
└── go.sum

Dependencies

Running Tests

go test -v ./...

Thank You

  • Charm for Bubble Tea and Lip Gloss — the Go TUI ecosystem that makes terminal apps a pleasure to build
  • BurntSushi for the rock-solid TOML parser
  • GitHub CLI for making multi-account switching possible from the command line

License

MIT

About

A terminal UI for toggling between git and GitHub identities.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages