Skip to content

Commit b9e0f62

Browse files
committed
chore: update README.md
1 parent a3be089 commit b9e0f62

2 files changed

Lines changed: 151 additions & 32 deletions

File tree

‎README.md‎

Lines changed: 151 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
1-
# git-workspace
1+
<p align="center">
2+
<img src="banner.png" width="800" />
3+
</p>
24

3-
> One repo. Many branches. Zero context-switching friction.
5+
<h3 align="center">git-workspace</h1>
6+
<h6 align="center">One repo. Many branches. Zero context-switching friction.</h4>
47

5-
`git-workspace` is an opinionated CLI that wraps [git worktrees](https://git-scm.com/docs/git-worktree) with a lifecycle system — so switching between branches feels like switching between projects, not shuffling stashes.
8+
<hr/>
69

7-
<!-- DEMO VIDEO PLACEHOLDER -->
10+
`git-workspace` is an opinionated git plugin that wraps [git worktrees](https://git-scm.com/docs/git-worktree) with a lifecycle system — so switching between branches feels like switching between projects, not shuffling stashes.
811

9-
---
10-
11-
## The problem it solves
12+
#### The problem it solves
1213

1314
`git stash`, `git switch`, re-run your dev server, restore your editor tabs. Repeat twenty times a day.
1415

15-
With `git-workspace`, each branch lives in its own directory. You `up` into it, your environment is ready. You `down` out of it, your teardown scripts run. You come back tomorrow and everything is exactly where you left it.
16+
With `git-workspace`, each branch lives in its own directory. You `up` into it, your environment is ready — dependencies installed, config files in place, hooks executed. You `down` out of it, your teardown scripts run. You come back tomorrow and everything is exactly where you left it.
17+
18+
#### Table of contents
19+
20+
- [Features](#features)
21+
- [Demo](#demo)
22+
- [How it works](#how-it-works)
23+
- [Installation](#installation)
24+
- [Quick start](#quick-start)
25+
- [Commands](#commands)
26+
- [Workspace manifest](#workspace-manifest)
27+
- [Lifecycle hooks](#lifecycle-hooks)
28+
- [Assets: links and copies](#assets-links-and-copies)
29+
- [Pruning stale worktrees](#pruning-stale-worktrees)
30+
- [Detached mode](#detached-mode)
31+
- [Debugging](#debugging)
32+
- [Development](#development)
1633

1734
---
1835

1936
## Features
2037

2138
- 🌳 **Worktree-per-branch** — every branch gets its own directory; no more dirty working trees
2239
- ⚡ **Lifecycle hooks** — run scripts on setup, activation, attachment, deactivation, and removal
23-
- 🔗 **Symlink injection** — link dotfiles and config from a shared config repo into every worktree automatically
24-
- 🔒 **Override linking** — replace tracked files with symlinks without touching git history
40+
- 🔗 **Symlink injection** — link dotfiles and config from a shared config repo into every worktree
41+
- 📋 **File copying** — copy mutable config files that each worktree can edit independently
42+
- 🔒 **Override assets** — replace tracked files with symlinks or copies without touching git history
2543
- 📦 **Variables** — pass manifest-level and runtime variables into hooks as environment variables
26-
- 🧭 **CWD-aware** — omit `--root` and `[branch]` when you're already inside a workspace or worktree
44+
- 🧭 **CWD-aware** — detects when you're already inside a workspace or worktree
2745
- 🏗️ **Detached mode** — skip interactive hooks for headless, CI, or agent workflows
46+
- 🧹 **Stale worktree pruning** — clean up old worktrees by age with dry-run preview
47+
- 🎨 **Rich terminal UI** — styled output, progress bars, and sortable worktree tables
2848
- 🗂️ **Config as code** — workspace configuration lives in its own git repo, versioned and shareable
2949

3050
---
3151

52+
## Demo
53+
54+
TODO: Demo video
55+
56+
---
57+
3258
## How it works
3359

3460
A `git-workspace` workspace is a directory containing:
@@ -38,7 +64,7 @@ my-project/
3864
├── .git/ ← bare git clone of your repository
3965
├── .workspace/ ← clone of your config repository
4066
│ ├── manifest.toml
41-
│ ├── assets/ ← files to be linked into worktrees
67+
│ ├── assets/ ← files to be linked or copied into worktrees
4268
│ └── bin/ ← lifecycle hook scripts
4369
├── main/ ← worktree for the main branch
4470
├── feature/
@@ -97,15 +123,20 @@ You're now inside `my-project/main/` — a real git worktree on the `main` branc
97123
| Command | Description |
98124
|---|---|
99125
| `git workspace init` | Initialize a new workspace in the current directory |
100-
| `git workspace clone <url>` | Clone an existing repository into workspace format |
101-
| `git workspace up [branch]` | Open a worktree, creating it if it doesn't exist |
102-
| `git workspace down [branch]` | Deactivate a worktree and run teardown hooks |
103-
| `git workspace reset [branch]` | Reapply links and re-run setup hooks |
104-
| `git workspace rm [branch]` | Remove a worktree (branch is preserved) |
105-
| `git workspace list` | List all active worktrees |
126+
| `git workspace clone` | Clone an existing repository into workspace format |
127+
| `git workspace up` | Open a worktree, creating it if it doesn't exist |
128+
| `git workspace down` | Deactivate a worktree and run teardown hooks |
129+
| `git workspace reset` | Reapply copies, links, and re-run setup hooks |
130+
| `git workspace rm` | Remove a worktree (branch is preserved) |
131+
| `git workspace ls` | List all active worktrees with branch, path, and age |
132+
| `git workspace prune` | Remove stale worktrees by age (dry-run by default) |
133+
| `git workspace root` | Print workspace root path; exits 0 if inside a workspace, 1 otherwise |
106134
| `git workspace edit` | Open the workspace config in your editor |
107135

108-
`[branch]` and `--root` can always be omitted when your shell is already inside a workspace or worktree.
136+
`[branch]` and `--root` let you operate on a workspace from anywhere in the file system, without needing to be inside it.
137+
138+
> [!TIP]
139+
> Use `git workspace --help` to explore all commands and flags in detail.
109140
110141
### Path output for automation
111142

@@ -136,7 +167,7 @@ base_branch = "main"
136167
# Variables injected into every hook as GIT_WORKSPACE_VAR_*
137168
[vars]
138169
node-version = "22"
139-
registry = "https://registry.npmjs.org"
170+
registry = "https://registry.npmjs.org"
140171

141172
# Lifecycle hooks (scripts in .workspace/bin/)
142173
[hooks]
@@ -148,13 +179,23 @@ on_remove = ["clean_cache"]
148179

149180
# Symlinks applied to every worktree
150181
[[link]]
151-
source = "dotfile" # path inside .workspace/assets/
152-
target = ".nvmrc" # path inside the worktree root
182+
source = "dotfile"
183+
target = ".nvmrc"
153184

154185
[[link]]
155186
source = "vscode-settings.json"
156187
target = ".vscode/settings.json"
157-
override = true # replaces an already-tracked file
188+
override = true
189+
190+
# File copies — each worktree gets its own mutable version
191+
[[copy]]
192+
source = "config.local.yaml"
193+
target = "config.local.yaml"
194+
195+
# Automatic cleanup rules
196+
[prune]
197+
older_than_days = 30
198+
exclude_branches = ["main", "develop"]
158199
```
159200

160201
---
@@ -168,9 +209,20 @@ Hooks are executable scripts stored in `.workspace/bin/`. They run with a rich s
168209
| `GIT_WORKSPACE_ROOT` | Absolute path to the workspace root |
169210
| `GIT_WORKSPACE_WORKTREE` | Absolute path to the current worktree |
170211
| `GIT_WORKSPACE_BRANCH` | Current branch name |
212+
| `GIT_WORKSPACE_BRANCH_NO_SLASH` | Branch name with `/` replaced by `_` |
171213
| `GIT_WORKSPACE_EVENT` | The lifecycle event that triggered the hook |
172214
| `GIT_WORKSPACE_VAR_*` | All manifest and runtime variables |
173215

216+
### Hook execution order
217+
218+
| Event | When it runs |
219+
|---|---|
220+
| `on_setup` | After a worktree is first created, or on `reset` |
221+
| `on_activate` | On every `up` (attached and detached) |
222+
| `on_attach` | On `up` in interactive mode only (skipped with `--detached`) |
223+
| `on_deactivate` | On `down`, `rm`, and `prune --apply` |
224+
| `on_remove` | On `rm` and `prune --apply`, after deactivation |
225+
174226
**Example hook** (`.workspace/bin/install_deps`):
175227

176228
```bash
@@ -189,18 +241,35 @@ git workspace up feature/my-feature -v env=staging -v debug=true
189241

190242
---
191243

192-
## Symlink linking
244+
## Assets: links and copies
245+
246+
Assets let you inject shared files — dotfiles, editor configs, secrets — into every worktree from your config repository. They live in `.workspace/assets/` and are applied automatically on `up` and `reset`.
193247

194-
Links let you inject shared files — dotfiles, editor configs, secrets — into every worktree from your config repository.
248+
### Links
195249

196-
- **Regular links** are added to `.git/info/exclude` so they stay invisible to git.
197-
- **Override links** (`override = true`) use `git update-index --skip-worktree` to silently replace a tracked file with your symlink.
250+
Symbolic links from `.workspace/assets` into the worktree. The source asset is shared across all worktrees — editing the link edits the original.
198251

199252
```toml
200253
[[link]]
201254
source = "env.local"
202255
target = ".env.local"
256+
```
257+
258+
### Copies
203259

260+
File copies from `.workspace/assets` into the worktree. Each worktree gets its own independent file. Copies are idempotent — `reset` overwrites them with a fresh copy from the source.
261+
262+
```toml
263+
[[copy]]
264+
source = "config.local.yaml"
265+
target = "config.local.yaml"
266+
```
267+
268+
### Override mode
269+
270+
By default, asset targets are added to `.git/info/exclude` so they stay invisible to git. Set `override = true` to replace a tracked file instead — the target is marked with `git update-index --skip-worktree` before the asset is applied.
271+
272+
```toml
204273
[[link]]
205274
source = "vscode-settings.json"
206275
target = ".vscode/settings.json"
@@ -209,6 +278,28 @@ override = true
209278

210279
---
211280

281+
## Pruning stale worktrees
282+
283+
Over time, worktrees accumulate. The `prune` command removes the ones you're no longer using:
284+
285+
```bash
286+
# preview what would be removed (default)
287+
git workspace prune --older-than-days 14
288+
289+
# actually remove them
290+
git workspace prune --older-than-days 14 --apply
291+
```
292+
293+
Deactivation and removal hooks run for each pruned worktree. Configure defaults in the manifest so you can just run `git workspace prune`:
294+
295+
```toml
296+
[prune]
297+
older_than_days = 30
298+
exclude_branches = ["main", "develop"]
299+
```
300+
301+
---
302+
212303
## Detached mode
213304

214305
For CI pipelines, automation, or agent workflows where you don't want interactive hooks to fire:
@@ -217,7 +308,24 @@ For CI pipelines, automation, or agent workflows where you don't want interactiv
217308
git workspace up main --detached
218309
```
219310

220-
This runs `on_setup` and `on_activate` but skips `on_attach`.
311+
This runs `on_setup` and `on_activate` but skips `on_attach`. Combine with `-o` for fully machine-readable output:
312+
313+
```bash
314+
WORKTREE=$(git workspace up main --detached -o)
315+
```
316+
317+
---
318+
319+
## Debugging
320+
321+
Set `GIT_WORKSPACE_LOG_LEVEL` to get diagnostic output on stderr:
322+
323+
```bash
324+
GIT_WORKSPACE_LOG_LEVEL=DEBUG git workspace up main
325+
```
326+
327+
> [!NOTE]
328+
> Supported levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`. Logging is silent by default.
221329
222330
---
223331

@@ -239,12 +347,20 @@ uv run pytest
239347

240348
The test suite includes both unit tests and integration tests. Integration tests spin up real git repositories in temporary directories — no mocking.
241349

350+
**Lint and type check:**
351+
352+
```bash
353+
uv run ruff check src/ tests/
354+
uv run ruff format --check src/ tests/
355+
uv run ty check src/
356+
```
357+
242358
**Project layout:**
243359

244360
```
245361
src/git_workspace/
246362
├── cli/commands/ ← one file per command
247-
├── assets.py ← symlink management
363+
├── assets.py ← symlink and copy management
248364
├── errors.py ← exception hierarchy
249365
├── git.py ← subprocess wrappers for git
250366
├── hooks.py ← lifecycle hook runner
@@ -257,10 +373,13 @@ src/git_workspace/
257373

258374
## Disclaimer
259375

260-
I built `git-workspace` because it fits *my* way of working. The worktree-per-branch model, the hook lifecycle, the symlink injection — these are the exact primitives I was missing.
376+
I built `git-workspace` because it fits *my* way of working. The worktree-per-branch model, the hook lifecycle, the asset injection — these are the exact primitives I was missing.
377+
378+
> [!NOTE]
379+
> Developed and verified on macOS. Linux support is expected but untested. Windows is not supported.
261380
262-
If it turns out to be useful to you too, that's a bonus. Contributions and feedback are welcome, but this tool will always be shaped first by how I want to use it.
381+
If it turns out to be useful to you too, [consider supporting the project](https://buymeacoffee.com/simiosoft). Contributions and feedback are welcome!
263382

264383
---
265384

266-
*Built with [Typer](https://typer.tiangolo.com), and a deep appreciation for git worktrees.*
385+
*Built with [Typer](https://typer.tiangolo.com), [Rich](https://rich.readthedocs.io), and a deep appreciation for git worktrees.*

‎banner.png‎

2.86 MB
Loading

0 commit comments

Comments
 (0)