git-env-manager
v1.2.13
Published
Multi-git-profile manager with SSH key integration
Maintainers
Readme
Language: English | 한국어
git-env-manager
A CLI tool for managing multiple Git profiles and SSH keys.
Stop manually switching git config and ssh-add between your personal and work accounts. git-env-manager centralizes profile management with automatic directory-based switching via Git's native includeIf.
Quick Start
Install
npm install -g git-env-managerInitialize
ghem initThis creates ~/.git-env-manager/ with an empty configuration. Default language is English.
To initialize with Korean:
ghem init --lang koAdd a Profile
ghem add personalInteractive prompts will ask for:
- Git user.name
- Git user.email
- SSH key setup: Generate new key (recommended) or use an existing key
- Auto-switch directories (optional, comma-separated)
When you choose "Generate new key", ghem automatically runs ssh-keygen and displays the public key so you can add it to GitHub/GitLab.
Switch Profile (Manual)
ghem switch workSets the global git config and loads the SSH key into the agent.
List Profiles
ghem listDisplays all registered profiles with their emails and mapped directories.
How It Works
Directory-Based Auto-Switching
When you add a profile with directories (e.g., ~/work/), git-env-manager injects includeIf entries into your ~/.gitconfig:
[includeIf "gitdir:~/work/"]
path = ~/.git-env-manager/gitconfig-workAny Git repository under ~/work/ automatically uses the work profile's name, email, and SSH key. No shell hooks, no manual switching.
SSH Key Management
SSH keys are copied to ~/.git-env-manager/keys/{profile}/ with proper permissions (0600). Each profile's gitconfig uses core.sshCommand with -o IdentitiesOnly=yes to ensure the correct key is used.
Configuration
All configuration is stored in ~/.git-env-manager/:
~/.git-env-manager/
├── config.json # Profile definitions
├── keys/
│ ├── personal/
│ │ ├── id_ghem_personal
│ │ └── id_ghem_personal.pub
│ └── work/
│ ├── id_ghem_work
│ └── id_ghem_work.pub
├── gitconfig-personal # Generated per-profile gitconfig
└── gitconfig-workCommands
| Command | Description |
|---------|-------------|
| ghem init [--lang <locale>] | Create ~/.git-env-manager/ directory and initial config |
| ghem add <profile> | Add a new profile via interactive prompts |
| ghem switch <profile> | Switch global Git profile and SSH key |
| ghem delete <profile> | Delete a profile and its associated keys |
| ghem list | Show all registered profiles |
| ghem config set-lang <locale> | Set display language (en, ko) |
| ghem config set-prompt <on\|off> | Enable or disable shell prompt indicator |
| ghem completion | Output shell completion script |
| ghem prompt [--shell <shell>] | Output shell prompt indicator script |
| ghem status [--short] | Show current profile context for the working directory |
| ghem edit <profile> | Edit an existing profile interactively |
| ghem test <profile> [--host <hostname>] | Test SSH connection for a profile |
Both ghem and git-env-manager work as CLI commands.
SSH Key Setup
When running ghem add, you'll be prompted to choose how to set up the SSH key:
- Generate new key (recommended) — automatically creates a key pair at
~/.ssh/id_ghem_{profile}and displays the public key for you to register on GitHub/GitLab. - Use existing key — enter the path to an existing private key (e.g.,
~/.ssh/id_rsa).
If you prefer to generate keys manually before running ghem add:
ssh-keygen -C "[email protected]" -f ~/.ssh/id_ghem_personalThen choose "Use existing key" during ghem add and enter the path.
Commit Signing (SSH)
git-env-manager can automatically configure SSH-based commit signing for each profile. This uses the same SSH key that's already managed by the tool — no separate GPG key needed.
Enable During Setup
When running ghem add, you'll be prompted:
? Enable SSH commit signing? (requires Git >= 2.34) (y/N)Enable for Existing Profile
ghem edit personalToggle the commit signing option when prompted.
What It Configures
When enabled, the per-profile gitconfig includes:
[user]
signingkey = ~/.git-env-manager/keys/{profile}/{key}.pub
[commit]
gpgsign = true
[gpg]
format = sshAll commits in directories mapped to that profile will be signed automatically.
Verify on GitHub
- Go to Settings > SSH and GPG keys > New SSH key
- Set Key type to Signing Key
- Paste the same public key used for authentication
GitHub will show a "Verified" badge on signed commits.
Note: SSH commit signing requires Git >= 2.34. The profile's SSH key is reused for signing, so no additional key management is needed.
Language
git-env-manager supports English (en) and Korean (ko). Default is English.
Set language during initialization:
ghem init --lang koOr change it later:
ghem config set-lang koAll prompts, messages, and errors will be displayed in the selected language. Command descriptions in --help remain in English.
Shell Prompt Indicator
Show the current Git profile in your terminal prompt. The indicator updates automatically as you navigate between directories.
~/work/project [work] $
~/personal/blog [personal] $Setup
Add one line to your shell config:
Bash (~/.bashrc)
eval "$(ghem prompt --shell bash)"
PS1='\w $(__ghem_prompt)\$ 'Zsh (~/.zshrc)
eval "$(ghem prompt --shell zsh)"
RPROMPT='$(__ghem_prompt)'Fish (~/.config/fish/config.fish)
ghem prompt --shell fish | source
# Then use (__ghem_prompt) in your fish_prompt functionStarship (~/.config/starship.toml)
[custom.ghem]
command = "ghem status --short"
when = "test -f ~/.git-env-manager/config.json"
format = "[$output]($style) "
style = "bold cyan"The prompt function uses awk to parse config.json directly — no Node.js process is spawned, so there is no noticeable delay.
Toggle
The prompt indicator is enabled by default. To disable:
ghem config set-prompt offShell Completion
Bash
echo 'eval "$(ghem completion --shell bash)"' >> ~/.bashrcZsh
echo 'eval "$(ghem completion --shell zsh)"' >> ~/.zshrcTab completion supports command names, profile names for switch/delete/edit/test, and language options for config set-lang.
Safety
- Atomic writes:
~/.gitconfigis written to a temp file first, then renamed (POSIX-atomic) - Backup: Modifying
~/.gitconfigcreates a timestamped backup in~/.git-env-manager/ - Append-only: Existing gitconfig entries (LFS, difftool, mergetool, etc.) are never removed
- Key permissions: Private keys are set to
0600on copy
Requirements
- Node.js >= 20
- Git >= 2.13 (for
includeIfsupport) - macOS or Linux
License
MIT
