ggid 0.2.0

Git Identity Manager - A complete solution for managing multiple Git identities
# gid - Git Identity Manager

<p align="center">
  <strong>🔄 A complete solution for managing multiple Git identities</strong>
</p>

<p align="center">
  <a href="#features">Features</a><a href="#installation">Installation</a><a href="#quick-start">Quick Start</a><a href="#usage">Usage</a><a href="#configuration">Configuration</a><a href="#advanced">Advanced</a>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/rust-1.70+-orange.svg" alt="Rust Version">
  <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
  <img src="https://img.shields.io/badge/platform-Linux%20%7C%20macOS%20%7C%20Windows-lightgrey.svg" alt="Platform">
</p>

---

## ✨ Features

- 🚀 **One-click Switch** - Quickly switch between multiple Git identities
- 📋 **Smart Rules** - Automatically match identities based on path or remote URL
- 🔑 **SSH Integration** - Automatically configure SSH keys and ssh-agent
- 🔏 **GPG Signing** - Support commit signing key management
- 🪝 **Git Hooks** - Automatically check identity before commit
- 📊 **Audit** - Check for identity issues in commit history
- 🌍 **Cross-platform** - Native support for Linux, macOS, and Windows
-**High Performance** - Written in Rust, extremely fast startup

---

## 📦 Installation

### Build from Source

```bash
# Clone repository
git clone https://github.com/ygwa/gid.git
cd gid

# Install
cargo install --path .

# Or build release
cargo build --release
sudo cp target/release/gid /usr/local/bin/
```

### Download Binary

Download binaries for your platform from the [Releases](https://github.com/ygwa/gid/releases) page.

---

## 🚀 Quick Start

### 1. Add Identity

```bash
# Interactive add
gid add

# Or specify arguments
gid add --id work --name "John Doe" --email "john@company.com"

# Or use short flags
gid add -i work -n "John Doe" -e "john@company.com"
```

### 2. Switch Identity

```bash
# Switch identity for current project
gid switch work

# Switch global identity
gid switch -g personal
```

### 3. Set Rules (Auto Switch)

```bash
# Add path rule
gid rule add -t path -p "~/work/**" -i work

# Add remote URL rule
gid rule add -t remote -p "github.com/my-company/*" -i work

# Apply rules automatically
gid auto
```

### 4. Install Git Hook

```bash
# Install to current repository
gid hook install

# Or install globally
gid hook install -g
```

---

## 📖 Usage

```
gid - Git Identity Manager

Usage: gid <COMMAND>

Commands:
  switch       Switch to a specified identity [aliases: sw]
  list         List all identities [aliases: ls]
  current      Show current identity [aliases: c]
  add          Add a new identity
  remove       Remove an identity [aliases: rm]
  edit         Edit configuration file
  export       Export configuration
  import       Import configuration
  rule         Manage rules
  doctor       Check identity configuration in current directory
  auto         Automatically switch identity based on rules
  hook         Manage Git hooks
  audit        Audit identity information in commit history
  fix-commit   Fix identity information in commits
  completions  Generate shell completion scripts

Options:
  -h, --help     Print help
  -V, --version  Print version
```

### Identity Management

```bash
# List all identities
gid list

# Show current identity
gid current

# Add identity (interactive)
gid add

# Add identity (with SSH and GPG)
gid add --id work \
  --name "John Doe" \
  --email "john@company.com" \
  --ssh-key ~/.ssh/id_work \
  --gpg-key ABCD1234

# Using short flags
gid add -i work -n "John Doe" -e "john@company.com" \
  --ssh-key ~/.ssh/id_work \
  --gpg-key ABCD1234

# Remove identity
gid remove work
```

### Rule Management

```bash
# Add path rule
gid rule add -t path -p "~/work/**" -i work

# Add remote URL rule
gid rule add -t remote -p "github.com/company/*" -i work

# List all rules
gid rule list

# Test rule matching
gid rule test

# Remove rule
gid rule remove 0
```

### Check and Auto Switch

```bash
# Check identity configuration in current directory
gid doctor

# Auto fix
gid doctor --fix

# Auto switch based on rules
gid auto
```

### Git Hooks

```bash
# Install pre-commit hook (current repo)
gid hook install

# Install global hook
gid hook install -g

# Check hook status
gid hook status

# Uninstall hook
gid hook uninstall
```

### Audit

```bash
# Audit current repository
gid audit

# Audit specified directory
gid audit --path ~/projects
```

### Fix Commits

```bash
# Fix identity in the most recent commit
gid fix-commit

# Fix a specific commit
gid fix-commit abc1234

# Fix using a specific identity
gid fix-commit -i work

# Batch fix a range of commits
gid fix-commit -r HEAD~3..HEAD

# Fix without confirmation prompts
gid fix-commit -y
```

---

## ⚙️ Configuration

### Configuration File Location

- Linux/macOS: `~/.config/gid/config.toml`
- Windows: `%APPDATA%\gid\config\config.toml`

Can be customized via `GID_CONFIG_DIR` environment variable.

### Configuration Format

```toml
# Identity List
[[identities]]
id = "work"
name = "John Doe"
email = "john@company.com"
description = "Work Identity"
ssh_key = "~/.ssh/id_work"
gpg_key = "ABCD1234"
gpg_sign = true

[[identities]]
id = "personal"
name = "John Doe"
email = "john@gmail.com"
description = "Personal Identity"

# Rule List
[[rules]]
type = "path"
pattern = "~/work/**"
identity = "work"
priority = 100

[[rules]]
type = "remote"
pattern = "github.com/my-company/*"
identity = "work"
priority = 50

# Settings
[settings]
verbose = true
color = true
auto_switch = false
pre_commit_check = true
strict_mode = false
```

### Project Config (.gid)

Create a `.gid` file in the project root to specify the default identity:

```
work
```

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `GID_COLOR` | Enable/disable color output | `true` |
| `NO_COLOR` | Disable color output (standard) | - |
| `GID_VERBOSE` | Enable verbose output | from config |
| `GID_EDITOR` | Editor for `gid edit` | `EDITOR` |
| `GID_CONFIG_DIR` | Custom config directory | - |

---

## 📚 Advanced Documentation

For detailed information about advanced features, see:

- [SSH Integration]docs/ssh.md - SSH key management, ssh-agent, config
- [GPG Signing]docs/gpg.md - GPG key management and commit signing
- [Git Hooks]docs/hooks.md - Pre-commit hooks, bypass options

---

## 🐚 Shell Completion

```bash
# Bash
gid completions bash > /etc/bash_completion.d/gid

# Zsh
gid completions zsh > /usr/local/share/zsh/site-functions/_gid

# Fish
gid completions fish > ~/.config/fish/completions/gid.fish

# PowerShell
gid completions powershell > gid.ps1
```

---

## 🔧 Development

### Build

```bash
# Debug mode
cargo build

# Release mode
cargo build --release

# Run tests
cargo test
```

### Directory Structure

```
src/
├── main.rs           # Entry point
├── cli.rs            # CLI definition
├── commands/         # Command implementations
├── config/           # Configuration management
├── rules/            # Rule engine
├── git/              # Git operations
├── ssh/              # SSH management
├── gpg/              # GPG management
└── audit/            # Audit functionality
```

---

## 🤝 Contributing

Contributions are welcome. Please open an issue or submit a PR.

---

## 📄 License

MIT License - see [LICENSE](LICENSE) file.