Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 63 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<div align="center">

**SSH-First GitHub Account Management - Clean, Fast, and Isolated**
**SSH-First Multi-Platform Account Management - Clean, Fast, and Isolated**

*Now supporting GitHub, GitLab, and more!*

[![Go Version](https://img.shields.io/badge/Go-1.23+-blue)](https://golang.org/doc/devel/release.html)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand All @@ -23,6 +25,7 @@
- [Overview](#-overview)
- [The Problem](#-the-problem-we-solve)
- [Features](#-features)
- [Multi-Platform Support](#-multi-platform-support)
- [How It Works](#-how-it-works)
- [Installation](#-installation)
- [Quick Start](#-quick-start)
Expand All @@ -38,29 +41,30 @@

## 🎯 Overview

**gitshift** is a clean, focused CLI tool for managing multiple GitHub accounts with **complete SSH isolation**. No GitHub API dependencies, no complex TUI interfaces - just pure SSH-based account management that works.
**gitshift** is a clean, focused CLI tool for managing multiple Git accounts across **GitHub, GitLab, and other platforms** with **complete SSH isolation**. No complex API dependencies, no TUI interfaces - just pure SSH-based account management that works everywhere.

### Why gitshift?

Managing multiple GitHub accounts (work, personal, client projects) traditionally requires:
- Manual SSH config editing
Managing multiple Git accounts across different platforms (work GitHub, personal GitLab, client projects) traditionally requires:
- Manual SSH config editing for each platform
- Complex git configuration management
- Constant context switching
- Constant context switching between accounts
- Risk of pushing to wrong accounts
- SSH key conflicts and authentication failures
- Platform-specific authentication setup

**gitshift eliminates all of this** with a simple, SSH-first approach.
**gitshift eliminates all of this** with a simple, SSH-first, multi-platform approach.

---

## 🚨 The Problem We Solve

```mermaid
graph TD
A[Developer] -->|Switches Context| B{Multiple GitHub Accounts}
B -->|Work Account| C[❌ Wrong SSH Key Used]
B -->|Personal Account| D[❌ Git Config Conflict]
B -->|Client Account| E[❌ Authentication Failure]
A[Developer] -->|Switches Context| B{Multiple Git Accounts}
B -->|Work GitHub| C[❌ Wrong SSH Key Used]
B -->|Personal GitLab| D[❌ Git Config Conflict]
B -->|Client GitHub| E[❌ Authentication Failure]

C --> F[😀 Commit to Wrong Account]
D --> G[😀 Wrong Email in Commits]
Expand Down Expand Up @@ -91,13 +95,15 @@ graph TD

### Core Capabilities

- πŸ” **SSH-Only Approach** - No GitHub API dependencies required
- πŸ”„ **Complete Isolation** - Accounts never interfere with each other
- πŸ”‘ **Smart SSH Management** - Auto-generates and manages SSH keys
- 🌍 **Multi-Platform Support** - GitHub, GitLab, Bitbucket, and self-hosted
- πŸ” **SSH-First Approach** - Minimal API dependencies, works everywhere
- πŸ”„ **Complete Isolation** - Accounts never interfere across platforms
- πŸ”‘ **Smart SSH Management** - Auto-generates and manages SSH keys per platform
- ⚑ **Fast Switching** - Instant account transitions with validation
- πŸ›‘οΈ **Secure by Design** - SSH config with `IdentitiesOnly=yes`
- 🌐 **Known Hosts Management** - Auto-manages GitHub host keys
- πŸ›‘οΈ **Secure by Design** - Platform-specific SSH configs with `IdentitiesOnly=yes`
- 🌐 **Known Hosts Management** - Auto-manages host keys for all platforms
- πŸ“‹ **Auto Key Management** - Adds keys to ssh-agent and clipboard
- πŸ” **Auto Platform Detection** - Detects platform from repository URLs
- πŸ” **Account Discovery** - Finds existing SSH keys automatically

### Implemented Commands
Expand All @@ -118,6 +124,42 @@ All features documented below are **verified and implemented** in the codebase:

---

## 🌍 Multi-Platform Support

gitshift supports multiple Git hosting platforms out of the box:

### Supported Platforms

| Platform | Status | SSH | API | Notes |
|----------|--------|-----|-----|-------|
| **GitHub** | βœ… Full | βœ… | βœ… | Complete support |
| **GitHub Enterprise** | βœ… Full | βœ… | βœ… | Custom domains supported |
| **GitLab** | βœ… SSH | βœ… | ⚠️ | API in progress |
| **GitLab Self-Hosted** | βœ… SSH | βœ… | ⚠️ | Custom domains supported |
| **Bitbucket** | 🚧 Planned | - | - | Coming soon |

### Platform-Specific Examples

```bash
# Add GitHub account
gitshift add personal --platform github --email john@personal.com

# Add GitLab account
gitshift add gitlab-personal --platform gitlab --email john@personal.com

# Add self-hosted GitLab
gitshift add company-gitlab --platform gitlab --domain gitlab.company.com

# Switch between platforms
gitshift switch personal # GitHub account
gitshift switch gitlab-personal # GitLab account
gitshift switch company-gitlab # Self-hosted GitLab
```

**See detailed documentation:** [docs/MULTI_PLATFORM_SUPPORT.md](docs/MULTI_PLATFORM_SUPPORT.md)

---

## πŸ”„ How It Works

### Account Switching Flow
Expand All @@ -129,16 +171,16 @@ sequenceDiagram
participant SSH Config
participant Git Config
participant SSH Agent
participant GitHub
participant Platform

User->>gitshift: gitshift switch work
gitshift->>gitshift: Validate account exists
gitshift->>SSH Config: Update ~/.ssh/config
gitshift->>gitshift: Validate account & detect platform
gitshift->>SSH Config: Update ~/.ssh/config (platform-specific)
gitshift->>Git Config: Set user.name & user.email
gitshift->>SSH Agent: Clear old keys
gitshift->>SSH Agent: Load work SSH key
gitshift->>GitHub: Test SSH connection
GitHub-->>gitshift: Authentication successful
gitshift->>SSH Agent: Load account SSH key
gitshift->>Platform: Test SSH connection
Platform-->>gitshift: Authentication successful
gitshift-->>User: βœ… Switched to work account
```

Expand Down
177 changes: 176 additions & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ config_version: "1.0.0"
| `name` | string | βœ… | Git user.name |
| `email` | string | βœ… | Git user.email (must be valid email) |
| `ssh_key_path` | string | ❌ | Path to SSH private key file |
| `github_username` | string | βœ… | GitHub username |
| `platform` | string | ❌ | Platform type: `github`, `gitlab`, `bitbucket` (default: `github`) |
| `domain` | string | ❌ | Platform domain (e.g., `github.com`, `gitlab.company.com`) |
| `username` | string | βœ… | Platform-specific username |
| `github_username` | string | ⚠️ | **Deprecated:** Use `username` with `platform: github` |
| `api_endpoint` | string | ❌ | Custom API endpoint for self-hosted platforms |
| `description` | string | ❌ | Human-readable description |
| `is_default` | boolean | ❌ | Whether this is the default account |
| `status` | string | ❌ | Account status (active, pending, disabled) |
Expand Down Expand Up @@ -147,6 +151,177 @@ client-project:
is_default: false
status: active
created_at: "2025-01-15T12:00:00Z"
```

---

## 🌍 **Multi-Platform Configuration**

gitshift supports multiple Git hosting platforms including GitHub, GitLab, GitHub Enterprise, and self-hosted instances.

### **Supported Platforms**

| Platform | Value | SSH Support | API Support | Notes |
|----------|-------|-------------|-------------|-------|
| GitHub | `github` | βœ… Full | βœ… Full | Default platform |
| GitHub Enterprise | `github` | βœ… Full | βœ… Full | Requires custom domain |
| GitLab | `gitlab` | βœ… Full | ⚠️ Basic | SSH fully functional |
| GitLab Self-Hosted | `gitlab` | βœ… Full | ⚠️ Basic | Requires custom domain |
| Bitbucket | `bitbucket` | 🚧 Planned | 🚧 Planned | Coming soon |

### **Platform-Specific Account Examples**

#### **GitHub Account (Default)**
```yaml
personal-github:
alias: personal-github
name: John Doe
email: john@personal.com
ssh_key_path: ~/.ssh/id_ed25519_github_personal
platform: github # Can be omitted, defaults to github
username: johndoe
description: Personal GitHub account
is_default: true
```

#### **GitLab Account**
```yaml
personal-gitlab:
alias: personal-gitlab
name: John Doe
email: john@personal.com
ssh_key_path: ~/.ssh/id_ed25519_gitlab_personal
platform: gitlab
username: johndoe
domain: gitlab.com # Optional for gitlab.com
description: Personal GitLab account
```

#### **GitHub Enterprise**
```yaml
work-github:
alias: work-github
name: John Doe
email: john@company.com
ssh_key_path: ~/.ssh/id_ed25519_github_enterprise
platform: github
username: jdoe
domain: github.company.com # Required for enterprise
api_endpoint: https://github.company.com/api/v3 # Optional
description: Work GitHub Enterprise account
```

#### **Self-Hosted GitLab**
```yaml
company-gitlab:
alias: company-gitlab
name: John Doe
email: john@company.com
ssh_key_path: ~/.ssh/id_ed25519_gitlab_company
platform: gitlab
username: jdoe
domain: gitlab.company.com # Required for self-hosted
api_endpoint: https://gitlab.company.com/api/v4 # Optional
description: Company GitLab instance
```

### **Multi-Platform Configuration Example**

Complete configuration with multiple platforms:

```yaml
accounts:
# GitHub accounts
personal-github:
alias: personal-github
platform: github
username: johndoe
name: John Doe
email: john@personal.com
ssh_key_path: ~/.ssh/id_ed25519_github_personal
is_default: true

work-github:
alias: work-github
platform: github
username: jdoe-work
name: John Doe
email: john@work.com
ssh_key_path: ~/.ssh/id_ed25519_github_work

# GitLab accounts
personal-gitlab:
alias: personal-gitlab
platform: gitlab
username: johndoe
name: John Doe
email: john@personal.com
ssh_key_path: ~/.ssh/id_ed25519_gitlab_personal

# Self-hosted GitLab
client-gitlab:
alias: client-gitlab
platform: gitlab
domain: gitlab.client.com
username: jdoe
name: John Doe
email: john@client.com
ssh_key_path: ~/.ssh/id_ed25519_gitlab_client

current_account: personal-github
```

### **Platform Detection**

gitshift automatically detects the platform from repository URLs:

```bash
# GitHub
git@github.com:user/repo.git β†’ Platform: github
https://github.com/user/repo.git β†’ Platform: github

# GitLab
git@gitlab.com:user/repo.git β†’ Platform: gitlab
https://gitlab.com/user/repo.git β†’ Platform: gitlab

# Self-hosted
git@gitlab.company.com:user/repo.git β†’ Platform: gitlab (custom domain)
```

### **Platform Usage Examples**

```bash
# Add GitHub account
gitshift add personal --platform github --email john@personal.com

# Add GitLab account
gitshift add gitlab-personal --platform gitlab --email john@gitlab.com

# Add self-hosted GitLab
gitshift add company-gitlab \
--platform gitlab \
--domain gitlab.company.com \
--email john@company.com

# Switch between platforms
gitshift switch personal-github # GitHub
gitshift switch gitlab-personal # GitLab
gitshift switch company-gitlab # Self-hosted GitLab
```

### **Backward Compatibility**

Existing GitHub-only configurations work without changes:

```yaml
# Old format (still works)
personal:
alias: personal
github_username: johndoe # Automatically mapped to username
# platform defaults to github
```

**Migration:** No action required. Add `platform` and `username` fields when convenient
last_used: "2025-01-16T07:30:00Z"
```

Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ This documentation provides comprehensive guides for using, configuring, and con

### **βš™οΈ Configuration & Setup**
- **[Configuration Guide](CONFIGURATION.md)** - Detailed configuration options
- **[Multi-Platform Configuration](CONFIGURATION.md#-multi-platform-configuration)** - GitHub, GitLab, and more
- **[Environment Variables](CONFIGURATION.md#environment-variables)** - Environment setup
- **[SSH Configuration](CONFIGURATION.md#ssh-configuration)** - SSH setup and management

### **πŸ”§ Usage & Features**
- **[Account Management](USER_GUIDE.md#account-management)** - Managing GitHub accounts
- **[Account Management](USER_GUIDE.md#account-management)** - Managing Git accounts across platforms
- **[SSH Key Management](USER_GUIDE.md#ssh-key-management)** - SSH key operations
- **[Account Switching](USER_GUIDE.md#account-switching)** - Switching between accounts
- **[Diagnostics](USER_GUIDE.md#diagnostics--health-checks)** - System health checks
Expand Down
Loading
Loading