Skip to main content

Git Account Switcher

CI PyPI Python Versions License: MIT

A Python CLI tool to easily switch between multiple Git SSH accounts. Manage multiple Git accounts with separate SSH keys and switch between them seamlessly.

Features

  • Manage multiple Git accounts with separate SSH keys
  • Switch between accounts easily — one command, no fuss
  • Generate SSH keys automatically (rsa, ed25519, ecdsa, and more)
  • Optional passphrase support for SSH keys
  • Colored terminal output with active account indicator
  • Pre-commit hook to prevent commits with the wrong account
  • Shell autocomplete for bash and zsh
  • Cross-platform support (Linux / macOS)

Installation

pip install gitacc-switcher

From source

git clone https://github.com/ktechhub/gitacc_switcher.git
cd gitacc_switcher
pip install .

Quick start

# 1. Add your accounts
gitacc add                    # prompts for name, email, optional passphrase
gitacc add --type ed25519     # specify key type

# 2. Switch between them
gitacc switch work            # full form
gitacc work                   # shorthand — same thing

# 3. See what's registered (active account is marked with *)
gitacc list

# 4. Prevent wrong-account commits in a repo
gitacc init work              # sets expected account + installs pre-commit hook
gitacc verify                 # manual check

Commands

gitacc add [--type TYPE]

Add a new Git account. Prompts for:

  • Account identifier (used in key filename and as a reference)
  • Git display name (defaults to account identifier)
  • Email
  • Optional SSH key passphrase

Available key types: rsa (default), ed25519, ecdsa, ecdsa-sk, ed25519-sk, dsa

gitacc add
gitacc add --type ed25519

gitacc switch <account> / gitacc <account>

Switch to a registered account. Clears all keys from the SSH agent, loads only this account's key, and sets git config --global user.name/email.

gitacc switch mywork
gitacc mywork          # shorthand

The SSH agent must already be running (eval $(ssh-agent)). If it isn't, gitacc will tell you.

gitacc list

List all registered accounts. The currently active account (matching global git config) is marked with *.

gitacc list
# Registered accounts:
#   * work → Git name: Jane Doe (jane@company.com) (active)
#   - personal (jane@personal.com)

gitacc remove [account]

Remove an account and its SSH keys. Prompts for confirmation.

gitacc remove mywork
gitacc remove          # prompts for account name

gitacc update <account> [--name NAME] [--email EMAIL]

Update the Git display name and/or email for an existing account. Prompts for any field not provided as a flag.

gitacc update mywork --name "Jane Doe"
gitacc update mywork --email "jane@newcompany.com"
gitacc update mywork   # prompts for both

gitacc init <account>

Bind the current repository to an account and install a pre-commit hook. Any commit attempt with a mismatched account will be blocked.

cd ~/projects/work-repo
gitacc init mywork

gitacc verify

Check whether the current Git identity matches the account expected by this repository.

gitacc verify

gitacc logout

Kill the SSH agent and unset the global Git user config.

gitacc logout

gitacc autocomplete install

Install tab-completion for your shell (bash or zsh). After running, restart your shell or source your profile.

gitacc autocomplete install

Completions cover: all command names, account names (for switch, remove, init, update), and key types (for add --type).

gitacc --version

gitacc --version
# gitacc 0.1.0

How pre-commit validation works

  1. gitacc init mywork stores gitacc.expected-account = mywork in the repo's local git config and writes a pre-commit hook.
  2. On every git commit, the hook reads ~/.gitacc and compares the expected account's name/email against the current git config user.*.
  3. If they don't match, the commit is blocked with a helpful message pointing to gitacc switch.

File layout

Path Purpose
~/.gitacc Stores all account entries (INI format)
~/.ssh/id_<type>_<account> Private SSH key per account
~/.ssh/id_<type>_<account>.pub Public SSH key per account

~/.gitacc format:

[mywork]
    name = Jane Doe
    email = jane@company.com
    private_key = /home/jane/.ssh/id_ed25519_mywork
    public_key = /home/jane/.ssh/id_ed25519_mywork.pub

Requirements

  • Python 3.8+
  • Git
  • SSH tools (ssh-keygen, ssh-agent, ssh-add) in PATH

Changelog

See CHANGELOG.md for a full history of changes.

Versions and the changelog are generated automatically by Release Please from Conventional Commit PR titles on main — feat: bumps minor, everything else bumps patch, and ! after the type (e.g. feat!:) bumps major. See CONTRIBUTING.md for the full commit/branch convention.

Contributing

See CONTRIBUTING.md for setup instructions, commit conventions, and the PR process.

License

MIT — see LICENSE for details.

Metadata

Release files for gitacc-switcher 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitacc-switcher 1.0.3
File Size Uploaded
gitacc_switcher-1.0.3.tar.gz 26.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gitacc-switcher 1.0.3
File Interpreter ABI Platform
gitacc_switcher-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 56.1 kB

Release files / gitacc_switcher-1.0.3.tar.gz

Download URL gitacc_switcher-1.0.3.tar.gz
Size 26.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e71d85adb59944d99585dbdca49fd35b048649aad17bf07631a1cb0292138d1b
BLAKE2b-256 checksum
How to use checksums
1f03cc8868581c332ebee8e6ee2aef16ffeb655b533f84c4ff7020c65309823e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / gitacc_switcher-1.0.3-py3-none-any.whl

Download URL gitacc_switcher-1.0.3-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ffcb590175e240ca61074fc0a9618b37859d4b57beac5340a42cf1b8ef79edf
BLAKE2b-256 checksum
How to use checksums
da9db0c45d6422930db5381ff00dda149aa57218fbda2d761a8eddbd07191b62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page