Skip to content

abdozkaya/git-swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

git-swap ๐Ÿ”„

Typing SVG

Stop committing with the wrong email! Switch Git identities instantly.

git-swap is a lightweight, zero-dependency CLI tool written in Go. It allows developers to manage multiple Git identities (Personal, Work, Freelance) and switch between them on a per-project basis with a single command.

It handles not just user.name and user.email, but also manages project-specific SSH keys (core.sshCommand), ensuring you never get "Permission denied" errors again.

๐Ÿš€ Features

  • โšก๏ธ Instant Switch: Change identity locally for the current repository without affecting global settings.
  • ๐Ÿ”‘ SSH Key Management: Automatically sets specific SSH keys for specific profiles.
  • ๐Ÿ” Commit Signing: Supports GPG and SSH signing keys. Auto-enables signing per profile.
  • ๐Ÿ›  CLI Managed: No manual JSON editing needed. Add, edit, and remove profiles interactively.
  • ๐Ÿ‘€ Status Check: Verify which profile is currently active in your repo.
  • ๐Ÿ“ฆ Cross-Platform: Works on macOS, Linux, and Windows.

๐Ÿ“ฆ Installation

macOS & Linux

Install via the automatic script:

curl -sL https://raw.githubusercontent.com/abdozkaya/git-swap/main/install.sh | bash

Windows (PowerShell)

Run as Administrator:

iwr -useb https://raw.githubusercontent.com/abdozkaya/git-swap/main/install.ps1 | iex

Build from Source (Go required)

If you prefer to build it yourself:

git clone https://github.com/abdozkaya/git-swap.git
cd git-swap
go build -o git-swap main.go
sudo mv git-swap /usr/local/bin/

๐ŸŽฎ Usage

1. Create a Profile

The tool is interactive. You can add a new identity (e.g., "work") easily.

git-swap add work

It will ask for:

  • Name,
  • Email,
  • SSH Key Path (Optional: e.g., ~/.ssh/id_work),
  • Signing Key (Optional: GPG Key ID or SSH Public Key path for verified commits)

2. List Profiles

See all your configured identities.

git-swap list

3. Swap Identity

Navigate to any git repository and apply a profile.

cd ~/my-company-project
git-swap work

Output: โœ… Swapped to: work

4. Check Status

Not sure which identity is active in the current folder?

git-swap status

5. Edit or Remove

Update an existing profile or delete one.

Update details

git-swap edit work

Delete profile

git-swap remove work

โš™๏ธ How It Works

git-swap stores your profiles in a local configuration file (~/.git-swap-config.json). When you run git-swap <profile>, it executes the following git commands locally in your project:

git config --local user.name "Your Name"
git config --local user.email "email@company.com"

# If SSH Key is provided:
git config --local core.sshCommand "ssh -i /path/to/private_key -F /dev/null"

# If Signing Key is provided:
git config --local user.signingkey "key_id_or_pub_key"
git config --local commit.gpgsign true

This ensures your global git configuration (~/.gitconfig) remains untouched and clean.

๐Ÿค Contributing

Pull requests are welcome! Feel free to open an issue for any bugs or feature requests.

๐Ÿ“„ License

MIT

About

๐Ÿ”„ Context-aware Git identity manager. Switch between Work/Personal accounts (User & SSH keys) per project with a single command. Zero dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors