An opinionated git plugin that wraps git worktrees with a lifecycle system
Project description
git-workspace
Local environments with zero friction.
git-workspace is an opinionated git plugin that wraps git worktrees with a lifecycle system โ so switching between branches feels like switching between projects, not shuffling stashes.
The problem it solves
git stash, git switch, re-run your dev server, restore your editor tabs. Repeat twenty times a day.
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.
Table of contents
- Features
- Demo
- How it works
- Installation
- Quick start
- Commands
- Workspace manifest
- Lifecycle hooks
- Assets: links and copies
- Pruning stale worktrees
- Detached mode
- Debugging
- Development
Features
- ๐ณ Worktree-per-branch โ every branch gets its own directory; no more dirty working trees
- โก Lifecycle hooks โ run scripts on setup, activation, attachment, deactivation, and removal
- ๐ Symlink injection โ link dotfiles and config from a shared config repo into every worktree
- ๐ File copying โ copy mutable config files that each worktree can edit independently
- ๐ Override assets โ replace tracked files with symlinks or copies without touching git history
- ๐ฆ Variables โ pass manifest-level and runtime variables into hooks as environment variables
- ๐งญ CWD-aware โ detects when you're already inside a workspace or worktree
- ๐๏ธ Detached mode โ skip interactive hooks for headless, CI, or agent workflows
- ๐งน Stale worktree pruning โ clean up old worktrees by age with dry-run preview
- ๐จ Rich terminal UI โ styled output, progress bars, and sortable worktree tables
- ๐๏ธ Config as code โ workspace configuration lives in its own git repo, versioned and shareable
Demo
https://github.com/user-attachments/assets/27bf0e6e-ac8c-424e-b899-8601ac4d54b7
How it works
A git-workspace workspace is a directory containing:
my-project/
โโโ .git/ โ bare git clone of your repository
โโโ .workspace/ โ clone of your config repository
โ โโโ manifest.toml
โ โโโ assets/ โ files to be linked or copied into worktrees
โ โโโ bin/ โ lifecycle hook scripts
โโโ main/ โ worktree for the main branch
โโโ feature/
โ โโโ my-feature/ โ worktree for feature/my-feature
โโโ ...
Each subdirectory is a fully functional git worktree. You work inside them like normal repositories.
Installation
Requires Python 3.14+.
With uv (recommended):
uv tool install git-workspace-cli
With pip:
pip install git-workspace-cli
Once installed, git workspace is available as a git subcommand.
[!WARNING] Ensure your
uv/pipinstall path is in$PATH, so Git can locate thegit-workspaceexecutable.
Quick start
Start from an existing repository:
git workspace clone https://github.com/you/your-repo.git
cd your-repo
cd $(git workspace up hotfix/urgent -o)
Start a brand new project:
mkdir my-project && cd my-project
git workspace init
cd $(git workspace up main -o)
You're now inside my-project/main/ โ a real git worktree on the main branch.
Commands
[!TIP] Use
git workspace --helpto explore all commands and flags in detail.
| Command | Description |
|---|---|
git workspace init |
Initialize a new workspace in the current directory |
git workspace clone |
Clone an existing repository into workspace format |
git workspace up |
Open a worktree, creating it if it doesn't exist |
git workspace down |
Deactivate a worktree and run teardown hooks |
git workspace reset |
Reapply copies, links, and re-run setup hooks |
git workspace rm |
Remove a worktree (branch is preserved) |
git workspace ls |
List all active worktrees with branch, path, and age |
git workspace prune |
Remove stale worktrees by age (dry-run by default) |
git workspace root |
Print workspace root path; exits 0 if inside a workspace, 1 otherwise |
git workspace edit |
Open the workspace config in your editor |
[branch] and --root let you operate on a workspace from anywhere in the file system, without needing to be inside it.
Path output for automation
init, clone, and up accept an -o / --output flag that prints the resulting path to stdout and suppresses all other output. This makes them composable with shell subexpressions:
# jump straight into a new worktree in one command
cd $(git workspace up feat/my-feature -o)
# clone a repo and land inside it immediately
cd $(git workspace clone https://github.com/you/your-repo.git -o)
# use in scripts without worrying about hook output polluting the result
WORKTREE=$(git workspace up feat/experiment --detached -o)
code "$WORKTREE"
Workspace manifest
The manifest lives at .workspace/manifest.toml and controls everything:
version = 1
base_branch = "main"
# Variables injected into every hook as GIT_WORKSPACE_VAR_*
[vars]
node-version = "22"
registry = "https://registry.npmjs.org"
# Lifecycle hooks (.workspace/bin/ scripts and inline commands)
[hooks]
on_setup = ["install_deps", "docker build . -t myproj:latest"]
on_activate = ["load_env"]
on_attach = ["open_editor"]
on_deactivate = ["save_state"]
on_remove = ["clean_cache"]
# Symlinks applied to every worktree
[[link]]
source = "dotfile"
target = ".nvmrc"
[[link]]
source = "vscode-settings.json"
target = ".vscode/settings.json"
override = true
# File copies โ each worktree gets its own mutable version
[[copy]]
source = "config.local.yaml"
target = "config.local.yaml"
# Automatic cleanup rules
[prune]
older_than_days = 30
exclude_branches = ["main", "develop"]
Lifecycle hooks
Each hook entry can be a script in .workspace/bin/ or an inline shell command. If the entry matches a file in .workspace/bin/, it runs as a script; otherwise it's executed via sh -c. Both forms receive the following environment variables:
| Variable | Value |
|---|---|
GIT_WORKSPACE_ROOT |
Absolute path to the workspace root |
GIT_WORKSPACE_NAME |
Workspace root directory name |
GIT_WORKSPACE_WORKTREE |
Absolute path to the current worktree |
GIT_WORKSPACE_BRANCH |
Current branch name |
GIT_WORKSPACE_EVENT |
The lifecycle event that triggered the hook |
GIT_WORKSPACE_VAR_* |
All manifest and runtime variables |
Hook execution order
| Event | When it runs |
|---|---|
on_setup |
After a worktree is first created, or on reset |
on_activate |
On every up (attached and detached) |
on_attach |
On up in interactive mode only (skipped with --detached) |
on_deactivate |
On down, rm, and prune --apply |
on_remove |
On rm and prune --apply, after deactivation |
Example hook (.workspace/bin/install_deps):
#!/bin/sh
# hooks already run from the worktree root โ no cd needed
node_version="$GIT_WORKSPACE_VAR_NODE_VERSION"
fnm use "$node_version" || fnm install "$node_version"
npm install
Mix bin scripts and inline commands in the same hook list:
[hooks]
on_setup = ["install_deps", "docker build . -t myproj:latest", "echo ready"]
Here install_deps runs .workspace/bin/install_deps, while docker build . -t myproj:latest and echo ready run as shell commands.
Pass runtime variables at call time with -v:
git workspace up feature/my-feature -v env=staging -v debug=true
Assets: links and copies
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.
Links
Symbolic links from .workspace/assets into the worktree. The source asset is shared across all worktrees โ editing the link edits the original.
[[link]]
source = "env.local"
target = ".env.local"
Copies
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.
[[copy]]
source = "config.local.yaml"
target = "config.local.yaml"
Override mode
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.
[[link]]
source = "vscode-settings.json"
target = ".vscode/settings.json"
override = true
Pruning stale worktrees
Over time, worktrees accumulate. The prune command removes the ones you're no longer using:
# preview what would be removed (default)
git workspace prune --older-than-days 14
# actually remove them
git workspace prune --older-than-days 14 --apply
Deactivation and removal hooks run for each pruned worktree. Configure defaults in the manifest so you can just run git workspace prune:
[prune]
older_than_days = 30
exclude_branches = ["main", "develop"]
Detached mode
For CI pipelines, automation, or agent workflows where you don't want interactive hooks to fire:
git workspace up main --detached
This runs on_setup and on_activate but skips on_attach. Combine with -o for fully machine-readable output:
WORKTREE=$(git workspace up main --detached -o)
Debugging
Set GIT_WORKSPACE_LOG_LEVEL to get diagnostic output on stderr:
GIT_WORKSPACE_LOG_LEVEL=DEBUG git workspace up main
Supported levels: DEBUG, INFO, WARNING, ERROR. Logging is silent by default.
Development
Clone and set up:
git clone https://github.com/ewilazarus/git-workspace.git
cd git-workspace
uv sync
Run the tests:
uv run pytest
The test suite includes both unit tests and integration tests. Integration tests spin up real git repositories in temporary directories โ no mocking.
Lint and type check:
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run ty check src/
Project layout:
src/git_workspace/
โโโ cli/commands/ โ one file per command
โโโ assets.py โ symlink and copy management
โโโ errors.py โ exception hierarchy
โโโ git.py โ subprocess wrappers for git
โโโ hooks.py โ lifecycle hook runner
โโโ manifest.py โ manifest parsing
โโโ worktree.py โ worktree model
โโโ workspace.py โ top-level workspace model
Disclaimer
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.
If it turns out to be useful to you too, consider supporting the project. Contributions and feedback are welcome!
[!NOTE] Developed and verified on macOS. Linux support is expected but untested. Windows is not supported.
Built with Typer, Rich, and a deep appreciation for git worktrees.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_workspace_cli-0.3.0.tar.gz.
File metadata
- Download URL: git_workspace_cli-0.3.0.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d3b244928c01285b94ba2891df79e14717abc0d9e55687177566e0daff953d3
|
|
| MD5 |
5c574727a452de343fe69b681bfca5d8
|
|
| BLAKE2b-256 |
2a2239fd02bdfde7ab7bb804e26a8efb5494b77dfaeab779c1c1d3fe6468e5e9
|
Provenance
The following attestation bundles were made for git_workspace_cli-0.3.0.tar.gz:
Publisher:
pypi.yml on ewilazarus/git-workspace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
git_workspace_cli-0.3.0.tar.gz -
Subject digest:
2d3b244928c01285b94ba2891df79e14717abc0d9e55687177566e0daff953d3 - Sigstore transparency entry: 1324055951
- Sigstore integration time:
-
Permalink:
ewilazarus/git-workspace@5e3f9fddc9755dfbdc61839e3687f25e5a084829 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ewilazarus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@5e3f9fddc9755dfbdc61839e3687f25e5a084829 -
Trigger Event:
push
-
Statement type:
File details
Details for the file git_workspace_cli-0.3.0-py3-none-any.whl.
File metadata
- Download URL: git_workspace_cli-0.3.0-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a21fbc30b99cf8812764c148cc8fcf7d5dd4ed3548b6cc6b2752b609fa152be0
|
|
| MD5 |
47565016e9a6a442024fba0d1e5eec43
|
|
| BLAKE2b-256 |
ccddfbc517da2c1517f5420b2ac6dfacd0190cd8939e4487b9f9ee32d92fda51
|
Provenance
The following attestation bundles were made for git_workspace_cli-0.3.0-py3-none-any.whl:
Publisher:
pypi.yml on ewilazarus/git-workspace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
git_workspace_cli-0.3.0-py3-none-any.whl -
Subject digest:
a21fbc30b99cf8812764c148cc8fcf7d5dd4ed3548b6cc6b2752b609fa152be0 - Sigstore transparency entry: 1324056040
- Sigstore integration time:
-
Permalink:
ewilazarus/git-workspace@5e3f9fddc9755dfbdc61839e3687f25e5a084829 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ewilazarus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@5e3f9fddc9755dfbdc61839e3687f25e5a084829 -
Trigger Event:
push
-
Statement type: