Skip to main content

gwork

gwork is a small Git worktree helper for the flows that happen all day in active repositories:

  • jump into an existing branch worktree
  • create a new branch in its own worktree
  • materialize a remote branch into a local worktree
  • delete a branch and its worktree together

The core CLI works anywhere Git and Python 3.10+ work. The -new flag is an optional macOS-only convenience for opening the target worktree in iTerm2.

New to worktrees? See docs/worktrees.md for a plain-English explanation and the full case for why gwork exists.

Also check out https://worktrunk.dev/, for more / slightly different worktree management workflows.

Why gwork

Git worktrees let each branch live in its own folder so you can work on multiple branches simultaneously — no stashing, no context switching. This is especially powerful with coding agents, where you can run several agents on separate features or fixes at the same time, each in its own isolated environment.

The raw Git commands add up fast. Without gwork, creating a new worktree means running git worktree add, manually cd-ing to the path, and copying over any local config files by hand. Switching to an existing one means running git worktree list to find the path, then cd-ing there yourself.

With gwork:

gw feature/auth          # jump to (or create) a worktree for this branch
gw -b feature/new-thing  # new branch in its own worktree
gw -d feature/old-thing  # delete worktree and branch together

One command handles the path, the git worktree plumbing, and copies files like .env automatically. With shell integration, it also cds you straight into the result.

→ Full breakdown with side-by-side comparisons: docs/worktrees.md

Install

From PyPI

pipx install gwork
uv tool install gwork
uvx gwork --help

pip install gwork also works, but pipx or uv tool install keeps CLI tools isolated from project environments.

From GitHub

pipx install git+https://github.com/v-ahuja/gwork.git
uv tool install git+https://github.com/v-ahuja/gwork.git
uvx --from git+https://github.com/v-ahuja/gwork.git gwork --help

Highly recommended next step after uv tool install:

gwork --install-shell-integration

That installs the gwork shell helper so gwork <branch> can switch worktrees and immediately cd into the result. Without shell integration, gwork still works, but it only prints the resolved path.

Required setup

Create a directory where gwork can place per-repo worktrees and export it in your shell startup:

mkdir -p "$HOME/worktrees"
export BASE_WORKTREE="$HOME/worktrees"

In fish, use set -Ux instead of export (a universal variable persists across sessions, so it does not need to go in config.fish):

mkdir -p "$HOME/worktrees"
set -Ux BASE_WORKTREE "$HOME/worktrees"

BASE_WORKTREE is required. gwork organizes worktrees under it by repository name.

Usage

Note: actual name here depends on the shell integration step. E.g. If you've named it gw then all commands below should be gw instead of gwork.

gwork main
gwork feature/foo
gwork -b feature/new-thing
gwork -base main -b feature/from-main
gwork -d feature/old-thing
gwork -D feature/broken-thing
git gwork feature/foo

Successful checkout and branch-creation commands print the absolute worktree path to stdout. That makes the plain CLI useful in scripts and also lets the shell helper cd automatically.

Shell integration (Highly recommended)

The CLI itself cannot change your current shell directory. If you want gwork to drop you directly into the returned worktree, source the generated helper:

gwork --install-shell-integration
gwork --install-shell-integration gw # if you want to name the shell integration `gw` instead. shorter and easier.
gwork --install-shell-integration gwork

# manual sourcing still works
source <(gwork --print-shell-integration)
source <(gwork --print-shell-integration zsh)
source <(gwork --print-shell-integration bash)
source <(gwork --print-shell-integration zsh --shell-integration-alias gwork)

zsh, bash, and fish are supported.

In fish, <(...) process substitution does not exist, so source the helper like this instead:

gwork --print-shell-integration fish | source

--install-shell-integration appends a managed block to ~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish and infers the shell from $SHELL. Missing parent directories are created, so a fresh fish install works without any manual setup. When you omit the alias, it prompts interactively and defaults to gw if you just hit Enter. Passing a name explicitly still works for scripting. --shell-integration-alias still applies to --print-shell-integration when you want to generate a different helper script without installing it.

The helper:

  • runs the gwork CLI
  • captures the printed worktree path
  • changes your current shell directory into the resolved worktree after switching to one or creating a new one
  • enables completion

The repository also includes checked-in copies under contrib/ for users who prefer to source a file directly.

macOS -new

-new {tab,window,split-h,split-v} opens the target worktree in iTerm2 via osascript. This mode is only supported on macOS, requires osascript on PATH, and requires iTerm2 to be running.

Worktree config and setup

The .gw folder contains the local repo config for gwork. Global/User level settings support will come shortly. The .gw folder is always copied when a new worktree is created.

The .gw/includes/manual_worktree file lets you copy more things when a new worktree is created. It

Currently, there's just one supported config - manual_includes. The manual_includes file is useful for automatically. This is useful for local ignored files such as .env, *.local, or config/.env.*.

Patterns use shell-style globs. Git-ignored directories are pruned while scanning so large ignored trees like node_modules/ are skipped.

E.g file

# .gw/includes/manual_worktree
.env
.credentials

Development

python3 -m venv .venv
source .venv/bin/activate
pip install -e .
python -m unittest discover -s tests

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gwork-0.1.4.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gwork-0.1.4-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file gwork-0.1.4.tar.gz.

File metadata

  • Download URL: gwork-0.1.4.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gwork-0.1.4.tar.gz
Algorithm Hash digest
SHA256 590b72b24bb2ff97891e178969a5331219fc3333bcd1f77aee36b7a12100f065
MD5 a0b3ff2abf501bd1bf361c2af92c1984
BLAKE2b-256 54559e1c776e3dc348620d7dca1cb638b71f20cab72e47022ffac6f190540468

See more details on using hashes here.

Provenance

The following attestation bundles were made for gwork-0.1.4.tar.gz:

Publisher: release.yml on v-ahuja/gwork

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gwork-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: gwork-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gwork-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 091048e5e6405d130a79b1edc70a8a9c7a8b93678723cafc70c646feceeb1172
MD5 7644a1f3396c539645b90a3349f3fcfb
BLAKE2b-256 d5eedaedd9b266d555e64bdfb3be1aeaa7732d9488598636d048aee4793d8191

See more details on using hashes here.

Provenance

The following attestation bundles were made for gwork-0.1.4-py3-none-any.whl:

Publisher: release.yml on v-ahuja/gwork

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 files

0.1.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page