Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

treefort

Python tests Build PyPI License: MIT

A CLI tool that helps you manage Git worktrees. Built as a GitHub CLI (gh) extension, but works standalone.

Dependencies: git, gh


Table of Contents


Quick Start

pip install treefort

Or with uv:

uvx treefort

Or download the PEX file from the releases page.

See recipes for hooks and templates.


Capabilities

Feature Description
Bare repository initialization Clean separation of git metadata from worktrees
Lifecycle hooks Custom scripts at key points with checksum validation
Global + project config Hooks and templates at both levels
PR worktrees Create worktrees directly from GitHub PRs
Project bootstrapping Auto-copy hooks/templates from repo on init
Worktree templates Pre-configured files copied to new worktrees
Environment variables Template variables with allowlist support

How It Works

Directory Structure

After initializing a repository (e.g., treefort):

treefort/
  .bare/                 # Bare git repository
  .git                   # Points to .bare/
  .treefort/
    hooks/             # Project-level hooks
    templates/         # Project-level templates
    config.toml        # Project configuration
  my-new-worktree/       # Created worktrees
    README.md
    ...

Hooks

Hooks are executable scripts that run at specific lifecycle points. They can be configured at:

  • Global level: ~/.treefort/hooks/ (or parent directories outside the project)
  • Project level: .treefort/hooks/ (copied from repo on init if present)

Execution order: global hooks first, then project hooks.

Hook Executes At Description
pre_init Global only Before initializing a repository for worktrees
post_init Global + Project After initializing a repository for worktrees
pre_checkout Global + Project Before checking out a PR or existing branch as a worktree
post_checkout Global + Project After checking out a PR or existing branch as a worktree
pre_create Global + Project Before creating a new worktree (branch)
post_create Global + Project After creating a new worktree (branch)
pre_remove Global + Project Before removing a worktree
post_remove Global + Project After removing a worktree

Hooks must be executable and allowed (via checksum validation) to run. Treefort stores approved hook checksums in ~/.treefort/allowed_hooks.json.

Example: post_create hook

A hook for this project might look something like:

#!/usr/bin/env bash

WORKTREE_NAME="$1"            # Full worktree name
BASE_REF="$2"                 # Format: remote/branch
WORKTREE_NAME_NORMALIZED="$3" # Worktree name with non-alphanumeric characters replaced by dashes

pushd "$WORKTREE_NAME"

uv venv
uv sync --group dev
prek install -f

popd

Templates

Files in .treefort/templates/ are copied to new worktrees before post-hooks execute.

Tip: Add template files to .gitignore.

Templates support environment variable substitution with ${ENVVAR_NAME} syntax. Add allowed variable names to allowed_envvars in ~/.treefort/config.toml.

Provided variables:

Variable Description
REPO_NAME Name of the git repository
REPO_DIR Absolute path of the repo / project directory
WORKTREE_NAME Name of the new worktree
WORKTREE_NAME_NORMALIZED Worktree name with non-alphanumeric chars replaced by dashes
WORKTREE_DIR Absolute path of the worktree directory
Example: JetBrains project name template

Set a unique project name per worktree in JetBrains IDEs:

File: .treefort/templates/.idea/.name

${REPO_NAME}.${WORKTREE_NAME_NORMALIZED}

Result in worktree: .idea/.name contains treefort.feat-my-branch


Commands

Run treefort without any arguments for usage information.

init — Initialize a repository for worktrees

Spec: init <repository_uri> [optional_clone_dir] [--yes]

Initializes a repository for use with worktrees. Similar to git clone — specify a directory name as the second argument, or it defaults to the repository name.

  • --yes: Automatically execute new or modified hooks without prompting
create — Create a new worktree

Spec: create <worktree_name> [base_ref] [--yes]

Creates a new worktree. Defaults to the default branch of the GitHub repository. Optionally specify a base reference.

  • --yes: Automatically execute new or modified hooks without prompting
checkout — Checkout a PR or branch as a worktree

Spec: checkout [--remote=<name>] [--yes] <branch_name|pr_number|pr_url>

Quickly create a worktree for a PR or existing branch. Works with fork PRs regardless of remote configuration.

  • --yes: Automatically execute new or modified hooks without prompting
remove — Remove a worktree

Spec: remove [--force] [--yes] [--delete-branch] <worktree_name>

Aliases: rm

Removes a worktree. Git refuses to delete worktrees with unmerged commits unless --force is used.

  • --delete-branch: Delete the local Git branch associated with the worktree
  • --yes: Automatically execute new or modified hooks without prompting
prune — Remove worktrees for merged pull requests

Spec: prune [--force] [--yes]

Finds worktrees whose local branch head matches a merged GitHub pull request. Unless you use --yes, treefort prompts before it removes each worktree and local branch.

  • --force: Bypass Git safety checks when treefort removes the worktree
  • --yes: Skip removal prompts and execute new or modified hooks without prompting
install — Install treefort

Spec: install [--alias=<name>] [--gh-ext] [--path-bin] [--force]

Installs treefort as a GitHub CLI extension or to your PATH. Without options, prompts for installation method.

  • --gh-ext: Install as gh extension
  • --path-bin: Install to ~/.local/bin or ~/bin
  • --alias: Custom name (e.g., wktr)
  • --force: Overwrite existing installation
version — Show version

Spec: version

Outputs the installed version of treefort.


Installation

Tested on Linux. Requires Python 3.10+ for PEX.

As a GitHub CLI extension (gh)

  1. Download the latest release binary.
  2. Make executable: chmod +x treefort
  3. Install: ./treefort install --gh-ext
  4. Test: gh treefort

Standalone

  1. Download the latest release binary or PEX.
  2. Make executable: chmod +x treefort*
  3. Install: ./treefort install --path-bin or ./treefort.pex install --path-bin
  4. Test: treefort version

Aliasing

./treefort install --alias=wktr --path-bin
wktr version

From source

git clone https://github.com/bjester/treefort.git
cd treefort
uv sync --group dev
source .venv/bin/activate
make dist/treefort
./dist/treefort install --path-bin

AI Disclosure

LLMs were used in the development of this project, mostly for brainstorming and bootstrapping code, particularly tests. The contribution proportion is roughly 80 / 20, human and AI code respectively. This may change over time as I try out agents!


License

MIT :: Copyright 2026 Blaine Jester

Metadata

Release files for treefort 0.5.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for treefort 0.5.0b2
File Interpreter ABI Platform
treefort-0.5.0b2-py3-none-any.whl Python 3 none any Details

Release files / treefort-0.5.0b2-py3-none-any.whl

Download URL treefort-0.5.0b2-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76f67d2d10c1bf4c6388046ed37c1520abacdfb7c2a045051194ec45c18f9b9d
BLAKE2b-256 checksum
How to use checksums
f46be571fa16618c6bac47f19154e1c3d82de150097decddedb0bf5263afc27e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Security for treefort 0.5.0b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 1 file in this release has been uploaded with provenance metadata.

Attestation for treefort-0.5.0b2-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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