/gitmorph

GitMorph is a powerful CLI tool that allows you to seamlessly switch between multiple Git identities on your local machine. Perfect for developers who work on different projects with various Git accounts.

Primary LanguageGo

GitMorph

GitMorph is a powerful CLI tool that allows you to seamlessly switch between multiple Git identities on your local machine. Perfect for developers who work on different projects with various Git accounts.

Screenshot 2024-10-12 at 2 22 09 AM

Features

  • Create and manage multiple Git profiles
  • Easily switch between different Git identities
  • List all available profiles
  • Simple and intuitive command-line interface

Installation

To install GitMorph, make sure you have Go installed on your system, then run:

go install github.com/abhigyan-mohanta/gitmorph

Update PATH

After installation, you may need to add the Go binaries directory to your system's PATH so you can run gitmorph from anywhere. Here are the steps:

  1. Check the directory where Go installs executables by running:

    go env GOPATH
  2. Open your .zshrc file for editing:

    nano ~/.zshrc
  3. Add the following line to include the Go binaries directory in your PATH:

    export PATH=$PATH:$(go env GOPATH)/bin
  4. Save the file and exit, then apply the changes:

    source ~/.zshrc

Usage

GitMorph provides the following commands:

Create a new profile

gitmorph new

This command will prompt you to enter a profile name, Git username, and Git email.

Switch to a profile

gitmorph switch <profile-name>

This command switches your global Git configuration to the specified profile.

List all profiles

gitmorph list

This command displays all available Git profiles.

How It Works

GitMorph stores your Git profiles in a JSON file located at ~/.gitmorph.json. When you switch profiles, it updates your global Git configuration using the git config --global command.

Code Structure

The project is structured as follows:

  • main.go: Entry point of the application
  • cmd/root.go: Defines the root command and common functionality
  • cmd/new.go: Implements the "new" command to create profiles
  • cmd/switch.go: Implements the "switch" command to change profiles
  • cmd/list.go: Implements the "list" command to display profiles

SSH Configuration

For seamless Git operations with multiple accounts, you can set up SSH configurations. Below is an example of how your SSH config file (~/.ssh/config) should look:

# Work GitHub Account
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519
    AddKeysToAgent yes
    
# Personal GitHub Account
Host github.com-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_personal
    AddKeysToAgent yes

Note on SSH Key Generation

To create an SSH key for your personal account, you can use the following command:

ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_personal

Usage Tips

  • When using the main id_ed25519.pub, the normal command for pushing changes works as expected:
git push -u origin main
  • For other accounts, you need to specify the SSH command:
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_ed25519_personal" git push -u origin main
  • Alternatively, you can configure the SSH command to use your SSH config file:
GIT_SSH_COMMAND="ssh -F ~/.ssh/config" git push -u origin main

Dependencies

GitMorph uses the following external libraries:

require (
    github.com/inconshreveable/mousetrap v1.1.0 // indirect
    github.com/spf13/cobra v1.8.1 // indirect
    github.com/spf13/pflag v1.0.5 // indirect
)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.