git-janus
v1.0.1
Published
Janus helps you switch between multiple Git accounts on a single machine
Readme
Janus
Manage multiple Git identities on a single machine — personal, work, or anything else.
How it works
Janus uses three native mechanisms that Git and SSH already support — it just wires them together for you automatically:
| Mechanism | What it does |
|---|---|
| ~/.janus/<profile>.gitconfig | Stores the name + email for each profile |
| ~/.gitconfig [includeIf "gitdir:..."] | Auto-applies the right identity based on which folder you're in |
| ~/.ssh/config Host block | Routes SSH auth to the correct key per profile |
Installation
# Install globally from npm
npm install -g git-janusThe CLI command is janus:
janus --helpOr run from source:
git clone https://github.com/dev-juri/git-janus.git
cd git-janus
npm install
npm run build
npm link # makes `janus` available globallyDuring development, use npm run dev -- instead of janus:
npm run dev -- add
npm run dev -- listQuick start
1. Add a profile
janus addYou'll be walked through:
- Profile name (e.g.
work) - Your full name and email for commits
- Git host (
github.com,gitlab.comorbitbucket.org) - Project folder — where your repos for this profile will live
- SSH key — auto-generate a new Ed25519 key, or point to an existing one
At the end, Janus will:
- Create the project folder if it doesn't exist
- Write
~/.janus/work.gitconfigwith your name, email, and URL rewrite rule - Append an
[includeIf]block to~/.gitconfig - Append a
Hostblock to~/.ssh/config
If a new SSH key was generated, the public key is shown and you can open your Git host's SSH key settings page directly from the prompt.
You can also pre-fill the project folder path as a flag:
janus add --dir ~/work2. That's it
Any repo cloned under the profile's project folder will automatically use that profile's identity:
cd ~/work
janus clone <repo url> # uses work SSH key + work identity automaticallyCommands
janus add [--dir <path>]
Interactive wizard to create a new profile. Automates:
- Project folder creation
- SSH key generation (or import of existing key)
~/.gitconfigpatching ([includeIf]block)~/.ssh/configpatching (Hostalias block)
janus clone <url> [destination] [git clone options]
Clones a repo using the correct SSH key for the active profile — no alias required. Detects the profile from the current directory, falling back to the last janus use selection.
cd ~/work
janus clone [email protected]:org/repo.git # standard SSH URL
janus clone https://github.com/org/repo.git # HTTPS — converted to SSH automatically
janus clone org/repo # shorthand
janus clone [email protected]:org/repo.git ~/dest # custom destinationAny extra flags are passed directly to git clone (--depth, --branch, etc.).
janus use <profile>
Manually sets a profile as the global Git identity fallback — affects all directories that don't have a matching [includeIf] block.
janus use workJanus saves your current identity before overwriting it, so you can restore it with
janus reset.
janus use <profile> --local
Sets the identity for the current repository only — writes to .git/config. Useful when a repo lives outside its profile's normal folder.
cd ~/some-other-place/work-repo
janus use work --localThis overrides everything — even [includeIf] blocks.
janus reset
Restores the global identity to what it was before the last janus use call.
janus use work # switches to work
# ... do work ...
janus reset # restores previous identity exactlyIf there's no snapshot (i.e. janus use was never run), janus reset fully unsets user.name and user.email from the global config, so Git falls back to whatever was in ~/.gitconfig before Janus was involved.
janus list
Shows all profiles in a table, with the currently active one highlighted.
janus list
# Profile Email Project Dir
# --------------------------------------------------------------------------------------
# ● work [email protected] /Users/jane/work/
# personal [email protected] /Users/jane/personaljanus status
Shows the effective Git identity in your current directory — and tells you whether it came from a folder match ([includeIf]) or the global fallback.
janus status
# Directory /Users/jane/work/acme/some-repo
# Identity Jane Doe <[email protected]>
# Profile work [folder-matched ✓]
# Global Jane <[email protected]> [personal]janus remove <profile>
Removes a profile after confirmation. Cleans up:
- The
Hostblock in~/.ssh/config - The
[includeIf]block in~/.gitconfig - The
~/.janus/<profile>.gitconfigfile
Your project folder is never deleted.
Using existing SSH keys
When running janus add, choose "I already have a key — enter path" when prompted for SSH key setup. Janus will reference your existing key without moving or modifying it.
To import multiple existing identities, run janus add once per profile and point each to its respective key file.
The global fallback pattern
If you manage your personal identity through your default ~/.gitconfig (without adding it as a Janus profile), you don't need to do anything special. Janus only appends [includeIf] blocks — it never overwrites your existing [user] section.
The recommended setup for this case:
janus add # add work profile only
# personal identity stays as-is in ~/.gitconfigIf you ever need to temporarily work globally under a different identity:
janus use work # overrides global; saves your personal identity first
# ... do work ...
janus reset # restores personal identity exactlyPlatforms
Works on macOS and Windows (Windows 10+ with OpenSSH). Uses os.homedir() for all path resolution so home directories are always correct regardless of platform.
