{"id":37072513,"url":"https://github.com/luongnv89/git-auto-switch","last_synced_at":"2026-01-14T08:30:48.044Z","repository":{"id":330809855,"uuid":"1124021303","full_name":"luongnv89/git-auto-switch","owner":"luongnv89","description":"A CLI tool for managing multiple GitHub accounts with automatic identity switching based on workspace folders.","archived":false,"fork":false,"pushed_at":"2025-12-28T09:00:29.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-30T14:20:47.736Z","etag":null,"topics":["cli","git-config"],"latest_commit_sha":null,"homepage":"https://luongnv.com","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luongnv89.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-28T06:31:52.000Z","updated_at":"2025-12-28T09:00:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/luongnv89/git-auto-switch","commit_stats":null,"previous_names":["luongnv89/git-auto-switch"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/luongnv89/git-auto-switch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luongnv89%2Fgit-auto-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luongnv89%2Fgit-auto-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luongnv89%2Fgit-auto-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luongnv89%2Fgit-auto-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luongnv89","download_url":"https://codeload.github.com/luongnv89/git-auto-switch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luongnv89%2Fgit-auto-switch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:16:59.381Z","status":"ssl_error","status_checked_at":"2026-01-14T08:13:45.490Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","git-config"],"created_at":"2026-01-14T08:30:47.087Z","updated_at":"2026-01-14T08:30:48.033Z","avatar_url":"https://github.com/luongnv89.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# git-auto-switch\n\n[![CI](https://github.com/luongnv89/git-auto-switch/actions/workflows/ci.yml/badge.svg)](https://github.com/luongnv89/git-auto-switch/actions/workflows/ci.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA CLI tool for managing multiple GitHub accounts with automatic identity switching based on workspace folders.\n\n## Features\n\n- Manage multiple GitHub accounts with separate SSH keys\n- **Multiple workspaces per account** - map several folders to the same identity\n- Automatic Git identity switching based on workspace folders\n- Pre-commit hook to prevent wrong-email commits\n- SSH key validation and GitHub authentication check during setup\n- Audit repositories and auto-fix identity issues\n- Automatic remote URL rewriting (HTTPS to SSH)\n- Show current active account for any directory\n\n## Requirements\n\n- Bash 3.2+\n- Git 2.13+ (for conditional includes)\n- jq (JSON processor)\n\n## Installation\n\n### Quick Install (curl)\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/luongnv89/git-auto-switch/main/install-curl.sh | bash\n```\n\nTo uninstall:\n```bash\ncurl -fsSL https://raw.githubusercontent.com/luongnv89/git-auto-switch/main/install-curl.sh | bash -s uninstall\n```\n\n### pip / uv\n\n```bash\npip install git-auto-switch\n# or\nuv pip install git-auto-switch\n```\n\n### npm\n\n```bash\nnpm install -g git-auto-switch\n```\n\n### From Source\n\n```bash\ngit clone https://github.com/luongnv89/git-auto-switch.git\ncd git-auto-switch\n\n# Install dependencies\nbrew install jq  # macOS\n# or: sudo apt install jq  # Ubuntu/Debian\n\n# Install CLI globally\nmake install\n```\n\n## Quick Start\n\n```bash\n# Initialize with your first account\ngit-auto-switch init\n# or use the short alias:\ngas init\n\n# Add more accounts\ngas add\n\n# Show current active account\ngas current\n# or:\ngas whoami\n\n# List all configured accounts\ngas list\n\n# Validate configuration\ngas validate\n\n# Audit repositories for identity issues\ngas audit\n\n# Audit and auto-fix issues\ngas audit --fix\n\n# Apply configuration after manual changes\ngas apply\n```\n\n## Commands\n\n| Command | Description |\n|---------|-------------|\n| `init` | Initialize configuration (first-time setup) |\n| `add` | Add a new account interactively |\n| `remove [id]` | Remove an account |\n| `list` | List all configured accounts |\n| `apply` | Apply configuration to system |\n| `validate` | Validate configuration and check for issues |\n| `audit [--fix]` | Audit repositories for identity mismatches (--fix to auto-fix) |\n| `current` | Show current active account for this directory (alias: `whoami`) |\n| `help` | Show help message |\n| `version` | Show version |\n\n## How It Works\n\n1. **SSH Keys**: Uses separate SSH keys for each account (generates ed25519 keys if needed)\n2. **SSH Config**: Adds host aliases (e.g., `gh-work`, `gh-personal`) to `~/.ssh/config`\n3. **Git Config**: Uses `includeIf.gitdir:` to auto-switch identity based on workspace\n4. **Pre-commit Hook**: Validates email before each commit to prevent mistakes\n5. **Remote Rewriting**: Converts `git@github.com` to `git@gh-alias` for proper SSH key usage\n\n## Workflow\n\n### Adding a New Account\n\nWhen you run `gas add`, the tool will:\n\n1. Prompt for account details (name, workspaces, SSH key, Git identity)\n2. Validate SSH key exists and test GitHub authentication\n3. Automatically proceed if validation passes (no manual confirmation needed)\n4. Apply configuration immediately\n5. Ask if you want to add another account\n\n### Checking Current Account\n\n```bash\n$ gas current\n\n========================================\n  Current Account: work\n========================================\n\n  Account ID:  work\n  Git Name:    John Doe\n  Git Email:   john@company.com\n  SSH Alias:   gh-work\n\n  Directory:   /home/user/workspace/work/project\n\n  Workspaces:\n    - ~/workspace/work\n    - ~/projects/company\n```\n\n### Fixing Issues\n\nThe `audit --fix` command automatically fixes:\n- **Email mismatches**: Removes local `user.email` so global `includeIf` takes over\n- **Wrong remotes**: Rewrites `git@github.com` to use the correct SSH alias\n\n```bash\n$ gas audit --fix\n\nIssues in: /home/user/workspace/work/repo1\n  Email:\n    Expected: john@company.com\n    Actual:   wrong@email.com\n  Fixed: Removed local user.email (will use global includeIf)\n```\n\n## Configuration\n\nConfiguration is stored in `~/.git-auto-switch/config.json`:\n\n```json\n{\n  \"version\": \"1.0.0\",\n  \"accounts\": [\n    {\n      \"id\": \"work\",\n      \"name\": \"Work Account\",\n      \"ssh_alias\": \"gh-work\",\n      \"ssh_key_path\": \"~/workspace/work/.ssh/id_ed25519\",\n      \"workspaces\": [\n        \"~/workspace/work\",\n        \"~/projects/company\"\n      ],\n      \"git_name\": \"John Doe\",\n      \"git_email\": \"john@company.com\"\n    }\n  ]\n}\n```\n\n## Multiple Workspaces\n\nEach account can have multiple workspace folders. All repositories within any of these folders will use the same Git identity and SSH key.\n\n**Use cases:**\n- Separate folders for different projects under the same account\n- Client work spread across multiple directories\n- Open source contributions in a dedicated folder\n\n**Adding workspaces during setup:**\n```\nWorkspace folder [~/workspace/work]: ~/workspace/work\nAdd another workspace? (leave empty to continue): ~/projects/company\nAdd another workspace? (leave empty to continue):\n```\n\n**Managing workspaces in the edit menu:**\n```\nOptions:\n  [2]   Manage workspaces (add/remove)\n\nWorkspace action: a\nNew workspace folder: ~/freelance/client-a\n```\n\n**Example output from `gas list`:**\n```\n[work] Work Account\n  Git:    John Doe \u003cjohn@company.com\u003e\n  SSH:    gh-work\n  Workspaces:\n    - ~/workspace/work\n    - ~/projects/company\n    - ~/freelance/client-a\n```\n\n## Cloning Repositories\n\nAlways use the SSH alias when cloning:\n\n```bash\n# For work account\ngit clone git@gh-work:org/repo.git\n\n# For personal account\ngit clone git@gh-personal:user/repo.git\n```\n\nExisting repositories with `git@github.com` remotes will be automatically rewritten when you run `gas apply` or `gas audit --fix`.\n\n## Rollback\n\nBackups are created automatically before any changes and stored in `~/.git-auto-switch/backup/\u003ctimestamp\u003e/`:\n\n```bash\n# List backups\nls ~/.git-auto-switch/backup/\n\n# Restore SSH config\ncp ~/.git-auto-switch/backup/\u003ctimestamp\u003e/ssh_config ~/.ssh/config\n\n# Restore Git config\ncp ~/.git-auto-switch/backup/\u003ctimestamp\u003e/gitconfig ~/.gitconfig\n```\n\n## Development\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.\n\n```bash\n# Install development dependencies\nbrew install shellcheck bats-core jq\n\n# Run linter\nmake lint\n\n# Run tests (59 tests)\nmake test\n\n# Run both\nmake all\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluongnv89%2Fgit-auto-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluongnv89%2Fgit-auto-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluongnv89%2Fgit-auto-switch/lists"}