Skip to main content

Git Account Switcher - Manage multiple Git SSH accounts easily

Project description

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.

Contributing

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

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitacc_switcher-1.0.2.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitacc_switcher-1.0.2-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file gitacc_switcher-1.0.2.tar.gz.

File metadata

  • Download URL: gitacc_switcher-1.0.2.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gitacc_switcher-1.0.2.tar.gz
Algorithm Hash digest
SHA256 910c3eb06c641b6d93551df3f94dd221a597de7fdc14bbae37bd2a6b5456a5e2
MD5 5bddb81fbf25d9fff6c3845ab375dc39
BLAKE2b-256 40174219580b2ecbb0e2914b9d071c22297e9a9c9905d4192090f077ba5577f6

See more details on using hashes here.

File details

Details for the file gitacc_switcher-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gitacc_switcher-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87757e309fb7efd76ffb1e11491e326bdc6185e0a976714ac0ab005564c9c7ee
MD5 979f66146e459bbe6e63ff3a854e65ff
BLAKE2b-256 26baba12d22b3a27677e28714972a45031cc8dad8ca5c0624293d1e88a23822f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page