Skip to content

dev-juri/git-janus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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-janus

The CLI command is janus:

janus --help

Or 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 globally

During development, use npm run dev -- instead of janus:

npm run dev -- add
npm run dev -- list

Quick start

1. Add a profile

janus add

You'll be walked through:

  • Profile name (e.g. work)
  • Your full name and email for commits
  • Git host (github.com, gitlab.com or bitbucket.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.gitconfig with your name, email, and URL rewrite rule
  • Append an [includeIf] block to ~/.gitconfig
  • Append a Host block 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 ~/work

2. 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 automatically

Commands

janus add [--dir <path>]

Interactive wizard to create a new profile. Automates:

  • Project folder creation
  • SSH key generation (or import of existing key)
  • ~/.gitconfig patching ([includeIf] block)
  • ~/.ssh/config patching (Host alias block)

janus clone <url> [destination] [git clone options]

Janus routes SSH auth through a per-profile alias (e.g. git@janus-work:) rather than bare git@github.com:. The URL rewrite that maps one to the other only kicks in once you're inside an existing repo — it can't apply during a fresh git clone because there's no .git directory yet for Git to match against. Without this command, you'd have to manually append -{profile} to every clone URL:

# without janus clone — error-prone every time
git clone git@github.com-work:org/repo.git

janus clone handles the substitution for you, so you keep using plain URLs:

cd ~/work
janus clone git@github.com: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 git@github.com:org/repo.git ~/dest   # custom destination

Profile is detected from the current directory, falling back to the last janus use selection. Any extra flags are passed directly to git clone (--depth, --branch, etc.).

cd ~/work
janus clone git@github.com: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 git@github.com:org/repo.git ~/dest   # custom destination

Any 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 work

Janus 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 --local

This 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 exactly

If 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                  jane@acme.com                   /Users/jane/work/
#     personal              jane@personal.com               /Users/jane/personal

janus 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 <jane@acme.com>
# Profile    work  [folder-matched ✓]
# Global     Jane <jane@personal.com>  [personal]

janus remove <profile>

Removes a profile after confirmation. Cleans up:

  • The Host block in ~/.ssh/config
  • The [includeIf] block in ~/.gitconfig
  • The ~/.janus/<profile>.gitconfig file

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 ~/.gitconfig

If 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 exactly

Platforms

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.

About

Janus helps you switch between multiple Git accounts on a single machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors