Workspace CLI (ws)
English | δΈζ
ws is a command-line tool designed to solve the pain points of multi-repository microservice development. By leveraging Git Worktrees, ws helps you effortlessly manage multiple service repositories under isolated, feature-specific workspaces.
No more constantly stashing changes, checking out branches, or dealing with mixed-up local environments when switching between different tasks.
π Features
- Isolated Feature Workspaces: Group multiple related microservices into a single directory based on a feature branch.
- Git Worktree Powered: Fast and lightweight. No need to clone repositories multiple times.
- Interactive Service Resolution: Fuzzy search for service names; if multiple match, interactively pick the one you need.
- Auto-Sync: Easily synchronize your local feature branches with their remote tracking branches.
- CoW Cache Warm-up (macOS): Copy-on-write clone git-ignored codegen directories (e.g. Kitex's
kitex_gen) from the main repo into new worktrees β near-instant, near-zero extra disk.
- Lifecycle Hooks: Run your own scripts before/after
ws add (e.g. fetch the latest base branch, install deps, open the IDE) via a simple convention under ~/.ws/hooks/.
- Self-Updating: Built-in update checker to ensure you are always using the latest version.
- Cross-Platform: Works on macOS, Linux, and Windows.
π¦ Installation
Option 1: Download Pre-compiled Binary (Recommended)
You can download the latest pre-compiled binaries for your operating system from the Releases page.
Option 2: Using go install
If you have Go installed (1.20+), you can install ws directly:
go install github.com/coegle/workspace_cli/cmd/ws@latest
βοΈ Configuration
Required
Before using ws, you need to tell it where your base repositories are located and where you want to create your feature workspaces.
# Set the directory where your main git clones live
ws config base_repos /path/to/your/main/repos
# Set the directory where new feature workspaces should be created
ws config base_ws /path/to/your/workspaces
By default, the configuration is stored in ~/.ws/config.yaml.
Optional
All of the following are optional β ws works out of the box with just the two settings above. See config.example.yaml for the full set (e.g. replace_slash, symlinks for sharing IDE configs across workspaces, and cow_dirs below).
CoW Cache Warm-up (macOS / APFS)
Some repos keep large git-ignored codegen outputs (e.g. Kitex's kitex_gen, Hertz's hertz_gen, or protobuf/gRPC generated gen/ dirs). Since these are ignored, git worktree add never checks them out, so every new worktree would have to regenerate them β slow and disk-hungry.
With cow_dirs, ws copy-on-write clones these directories from the main repo into each new worktree using APFS clonefile. The data blocks are shared with the main repo's copy, so it's near-instant and uses almost no extra disk.
# in ~/.ws/config.yaml
cow_dirs:
- kitex_gen
Notes:
- The donor is always the main repo (
base_repos/<service>/kitex_gen), so make sure you've run codegen there at least once.
- It's a pure cache/warm-up: cloned as-is with no IDL consistency check. If the worktree's IDL differs, just re-run codegen in the worktree.
- If the donor dir doesn't exist, the entry is silently skipped.
- Only works on the same APFS volume; cross-volume / non-APFS is skipped (never falls back to a full copy).
Lifecycle Hooks
ws can run your own scripts around ws add, letting you customize the workflow without modifying ws itself (e.g. fetch the latest base branch before creating worktrees, install dependencies, or auto-open the IDE afterwards).
Hooks are opt-in by convention: just drop an executable script at the expected path and ws will run it. If the script doesn't exist, it's silently skipped.
| Hook |
When it runs |
On failure |
~/.ws/hooks/pre-add |
Before the workspace is created |
Aborts ws add (non-zero exit) |
~/.ws/hooks/post-add |
After all worktrees are ready |
Best-effort; a warning is printed but ws still succeeds |
Each script receives the workspace context via environment variables:
| Variable |
Description |
WS_DIR |
Absolute path of the workspace directory |
WS_NAME |
Workspace (safe directory) name |
WS_BRANCH |
Feature branch name |
WS_REPOS |
base_repos path holding the source repositories |
Example β validate the branch name before creating, then open the IDE afterwards:
# ~/.ws/hooks/pre-add (remember: chmod +x)
#!/usr/bin/env bash
[[ "$WS_BRANCH" == feat/* ]] || { echo "branch must start with feat/"; exit 1; }
# ~/.ws/hooks/post-add (chmod +x)
#!/usr/bin/env bash
# The working directory is already $WS_DIR
code .
Notes:
- The script must be executable (
chmod +x); a non-executable file is skipped with a warning.
post-add runs in $WS_DIR; pre-add runs before that directory exists, so it uses the current directory instead.
1. Create a Workspace & Add Services
Imagine you are working on a new feature called feat_login that requires modifying the user_service and auth_service.
# Syntax: ws add [-b base_branch] <feature_branch> <service1> <service2> ...
ws add feat_login user_service auth_service
This command will:
- Create a new directory
feat_login in your base_ws path.
- Create a git worktree for
user_service on the branch feat_login.
- Create a git worktree for
auth_service on the branch feat_login.
Tip: If you want to branch off from a specific branch (e.g., origin/develop), use the -b flag: ws add -b origin/develop feat_login user_service.
2. Open Workspace in IDE
Quickly open the entire feature workspace in your IDE (currently supports GoLand):
ws open feat_login
3. Sync Branches
When the base branch (e.g., master) has updates, you can quickly fast-forward your local branches (if they haven't diverged):
ws sync user_service
4. Remove a Service from Workspace
Done with user_service? Remove it from the workspace without affecting the main repository:
ws remove feat_login user_service
5. Destroy the Workspace
Once the feature is merged and done, clean up the entire workspace:
ws destroy feat_login
(If there are uncommitted changes, ws will prompt you before destroying).
π Self Update
ws checks for updates periodically. If a new version is available, it will prompt you.
You can also trigger an update manually:
ws update
π License
This project is licensed under the MIT License - see the LICENSE file for details.