Git Account Switcher
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
gitacc switch work --local # only this repo, leave the global identity alone
# 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)
- 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> [--local] / 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
Pass --local/-l to set the identity for the current repository only (git config local scope), leaving the global user.name/user.email untouched. Must be run from inside a Git repository.
gitacc switch mywork --local
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
gitacc init myworkstoresgitacc.expected-account = myworkin the repo's local git config and writes a pre-commit hook.- On every
git commit, the hook reads~/.gitaccand compares the expected account's name/email against the currentgit config user.*. - 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) inPATH
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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gitacc_switcher-1.1.0.tar.gz | 27.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gitacc_switcher-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.6 kB
Release files / gitacc_switcher-1.1.0.tar.gz
| Download URL | gitacc_switcher-1.1.0.tar.gz |
|---|---|
| Size | 27.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0b53b73c759aca8b1d148a895387c0f914daeb9c8beb647275e200b4d4b4785
|
|
BLAKE2b-256 checksum How to use checksums |
9b830ea3b2971159e1203e0bade0df8d125db5c876da37c23dbe75812334b94a
|
| 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.1.0-py3-none-any.whl
| Download URL | gitacc_switcher-1.1.0-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abe48f1c75017b203fa6e67b4ced1e241e95c57876d2ba9de69ed3cae6f64bff
|
|
BLAKE2b-256 checksum How to use checksums |
331a9d15a7ef381480ebcc2ff685869aa6f05c8e9a305bb4fee889d29f22c37f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|