You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b9e0f62
Browse filesBrowse the repository at this point in the historyBrowse files
> One repo. Many branches. Zero context-switching friction.
5
+
<h3align="center">git-workspace</h1>
6
+
<h6align="center">One repo. Many branches. Zero context-switching friction.</h4>
4
7
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/>
6
9
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.
8
11
9
-
---
10
-
11
-
## The problem it solves
12
+
#### The problem it solves
12
13
13
14
`git stash`, `git switch`, re-run your dev server, restore your editor tabs. Repeat twenty times a day.
14
15
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)
16
33
17
34
---
18
35
19
36
## Features
20
37
21
38
- 🌳 **Worktree-per-branch** — every branch gets its own directory; no more dirty working trees
22
39
- ⚡ **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
25
43
- 📦 **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
27
45
- 🏗️ **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
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`.
193
247
194
-
Links let you inject shared files — dotfiles, editor configs, secrets — into every worktree from your config repository.
248
+
### Links
195
249
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.
198
251
199
252
```toml
200
253
[[link]]
201
254
source = "env.local"
202
255
target = ".env.local"
256
+
```
257
+
258
+
### Copies
203
259
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
204
273
[[link]]
205
274
source = "vscode-settings.json"
206
275
target = ".vscode/settings.json"
@@ -209,6 +278,28 @@ override = true
209
278
210
279
---
211
280
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
+
212
303
## Detached mode
213
304
214
305
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
217
308
git workspace up main --detached
218
309
```
219
310
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.
221
329
222
330
---
223
331
@@ -239,12 +347,20 @@ uv run pytest
239
347
240
348
The test suite includes both unit tests and integration tests. Integration tests spin up real git repositories in temporary directories — no mocking.
241
349
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
+
242
358
**Project layout:**
243
359
244
360
```
245
361
src/git_workspace/
246
362
├── cli/commands/ ← one file per command
247
-
├── assets.py ← symlink management
363
+
├── assets.py ← symlink and copy management
248
364
├── errors.py ← exception hierarchy
249
365
├── git.py ← subprocess wrappers for git
250
366
├── hooks.py ← lifecycle hook runner
@@ -257,10 +373,13 @@ src/git_workspace/
257
373
258
374
## Disclaimer
259
375
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.
261
380
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!
263
382
264
383
---
265
384
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.*
0 commit comments