Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Profile Switcher CLI (git-profile)

A simple, interactive CLI tool to manage and switch between multiple Git profiles (identities, SSH keys, GPG keys, and service credentials) seamlessly.

If you work across different Git profiles (e.g., personal GitHub, corporate GitHub, GitLab accounts), this tool eliminates the need to copy-paste names, emails, keys, and tokens.


Features

  • Multi-Identity Management: Define separate profiles with unique names, emails, GPG signing keys, SSH keys, and service usernames.
  • Smart Switch Scope:
    • Switch locally (git-profile use <name> --local) to write configurations directly to the repository's .git/config.
    • Switch globally (git-profile use <name> --global) to update your global git config.
    • Automatically runs --local if you are inside a Git repository, and --global otherwise.
  • Conflict-Free SSH Keys: Sets Git's core.sshCommand dynamically (ssh -i <key_path> -o IdentitiesOnly=yes) inside the repo. This avoids polluting your global ~/.ssh/config file.
  • Account Separation in Keychain: Configures Git's credential.https://<host>.username <username>, allowing the macOS Keychain helper (osxkeychain) to store separate API tokens or passwords for different profiles on the same host (e.g. github.com).
  • Environment Exporting: Inject Personal Access Tokens (like GITHUB_TOKEN) directly into your current terminal session via eval $(git-profile env <name>).
  • Zero External Dependencies: Fast, lightweight, and secure.

Installation

Via Homebrew (macOS)

brew tap pavelkortp/tap
brew install git-profile

Via NPM

npm install -g @p-pavlo/git-profile

Usage Guide

1. Interactive Help

To see all available commands, run:

git-profile --help

2. Add a New Profile

Create a profile interactively. You will be prompted to enter details for user name, email, SSH key path, GPG Key ID, and service token:

git-profile add [profile-name]

3. List Profiles

Display all configured profiles. The active global profile and current directory's active local profile will be highlighted:

git-profile list

4. Switch Profile

Switch to a specific profile:

# Apply locally to the current git repository (default behavior if inside a repo)
git-profile use work

# Force apply globally (updates ~/.gitconfig)
git-profile use personal --global

5. Export Tokens to Shell Session

To inject the profile's personal access token (GITHUB_TOKEN) and git variables into your current shell session (useful for GitHub CLI gh or script execution):

eval $(git-profile env work)

Configuration File

Profiles are stored locally in JSON format at: ~/.git-profiles.json


License

MIT

About

The interactive developer CLI that switches your Git profiles, GPG signing keys, SSH credentials, and HTTPS tokens instantly

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages